`

Ejb模糊搜索+分页语句

    博客分类:
  • Ejb3
阅读更多
     这是实现模糊搜索分页的完整的一个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;
}


   
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics