1 共通代码
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.hibernate.query.internal.NativeQueryImpl;
import org.hibernate.transform.Transformers;
public class UserDao{
@PersistenceContext
private EntityManager entityManager;
}
2 createQuery()
使用HQL语句实现查询,以hibernate生成的Bean为对象装入list返回 。
EntityManager entityManager;
String hql="Select * From User";
List<User> userList=entityManager.createQuery(hql);
3 createNativeQuery()
使用SQL语句实现查询。
3.1 查询List
/**
* 得到用户信息
*/
public List<SysUserDto> getUserList(String username, String jobNumer) {
String sql="select t1.user_id userId,t1.user_name userName,t1.postid postId,t1.jobnumer jobNumer,t1.dept_id deptId,t4.dept_nam