由将SQL查询结果转化为pojo的想到的
今天在网上上看见一篇“将SQL查询结果转化为pojo对象的”博客,博主自定义做了一个类如下:
import java.lang.reflect.Field;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.property.ChainedPropertyAccessor;
import org.hibernate.property.PropertyAccessor;
import org.hibernate.property.PropertyAccessorFactory;
import org.hibernate.property.Setter;
import org.hibernate.transform.ResultTransformer;
/**
* 完成native sql查询数据(数组)到pojo对象的转化
* @author warison
*
* Oct 26, 2009
*/
public class PojoTransformer implements ResultTransformer {
private static final long serialVersionUID = 1L;
private Class<? extends BaseModel> resultClass;
private Setter[] setters;
private PropertyAccessor propertyAccessor;
public PojoTransformer(Class<? extends BaseModel> resultClass) {
if(resultClass==null)
throw new IllegalArgumentException("resultClass cannot be null");
this.resultClass = resultClass;
propertyAccessor = new ChainedPropertyAccessor(new PropertyAccessor[] { PropertyAccessorFactory.getPropertyAccessor(resultClass,null), PropertyAccessorFactory.getPropertyAccessor("field")});
}
//结果转换时,HIBERNATE调用此方法
&n
相关文档:
如果你经常遇到下面的问题,你就要考虑使用SQL Server的模板来写规范的SQL语句了:
SQL初学者。
经常忘记常用的DML或是DDL SQL 语句。
在多人开发维护的SQL中,每个人都有自己的SQL习惯,没有一套统一的规范。
在SQL Server Management Studio中,已经给大家提供了很多常用的现成SQL规范模板。
SQL Server Management ......
SQL基本语句
一. SQL的四条最基本的数据操作语句为Insert,Select,Update和Delete。
二.首先我们使用CREATE TABLE语句来创建一个表。DDL语句对数据库对象如表、列和视进行定义。它们并不对表中的行进行处理,这是因为DDL语句并不处理数据库中实际的数据。这些工作由另一 ......
--SQL高级程序设计:子查询
use AdventureWorks
GO
SELECT DISTINCT EmployeeID from HumanResources.JobCandidate WHERE EmployeeID IS NOT NULL;
SELECT e.EmployeeID,FirstName,LastName
from HumanResources.Employee e
INNER JOIN Person.Contact c
ON e.ContactID = c.ContactID
WHERE e.EmployeeID IN ......
一、下载安装
1、SQL Server 2005 Express Edition
下载 SQL Server 2005 Express Edition(下载页面):
http://msdn.microsoft.com/vstudio/express/sql/download/
安装完数据库后设置ICP/IP协议启动(这一步不能少,默认是TCP/IP不启用的),具体如下:
(1)打开SQL Server Configuration Manager
(2)转到SQL S ......