读书人

Ejb模糊搜索+分页话语

发布时间: 2012-08-26 16:48:06 作者: rapoo

Ejb模糊搜索+分页语句
这是实现模糊搜索分页的完整的一个Ejb+SQL语句

经测试,已经通过了


public List<ThisIsAtest> searchBySearchKey(String SearchKey,
int pageSize, int pageNow) {
//先检查搜索的关键字
System.out.println("search the SearchKey key is: " + SearchKey);

List<TESTBEAN > thisIsAtest= null;

int first = pageSize * (pageNow - 1);

String sql = "select model from TESTBEAN model where model.srcName like '%"
+ SearchKey+ "%'";

try {
Query query = entityManager.createQuery(sql);
thisIsAtest = query.setMaxResults(pageSize).setFirstResult(first)
.getResultList();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("It didn't search the key is : " + scrName);
return null;
}
return thisIsAtest;
}


读书人网 >软件架构设计

热点推荐