[size=large]这是实现模糊搜索分页的完整的一个Ejb+SQL语句[/size]
经测试,已经通过了
[color=blue]
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;
}
[/color]
经测试,已经通过了
[color=blue]
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;
}
[/color]