【发布时间】:2014-03-24 11:51:22
【问题描述】:
您好,我正在编写一个条件查询来获取员工。我使用通用类型作为此方法的参数。用户可以动态地传递他们想要的类。对于我的员工类,我想动态添加一些限制,例如如果员工为真,那么我想获取该记录,否则不应获取该记录。但是如果用户只给出记录而没有任何限制,那么它必须获取所有记录。
public static <T> List getRowCount(Class<T> classname) {
Session ses = HibernateUtil.getSessionFactory().openSession();
System.out.println("classname" + classname);
List<SetPaginationRecords> s1 = new ArrayList<SetPaginationRecords>();
try {
Criteria crit1 = ses.createCriteria(classname);
crit1.setProjection(Projections.rowCount());
List l1 = crit1.list();
Iterator it1 = l1.iterator();
if (it1.hasNext()) {
Object o = it1.next();
totalNumberOfRecords = Integer.parseInt(o.toString());
}
}
}
这是我的调用方法。
List<SetPaginationRecords> paginationrecords = PaginationClass.getRowCount(EmployeeEntity.class);
request.setAttribute("paginationrecords", paginationrecords);
【问题讨论】:
-
嗨,谁能帮帮我。
标签: java hibernate hibernate-criteria