补充一下吧:我在一个controller函数里面要这样调用:
@RequestMapping("/complexFind")
public void complexFind(ComplexSearchForm searchForm,HttpServletRequest request,
HttpServletResponse response) throws Exception {
page=ServletRequestUtils.getIntParameter(request, "page", 1);//默认值为1
rows=ServletRequestUtils.getIntParameter(request, "rows", 0);
String hql=bookService.getCompleSearchHQL(searchForm);
books=bookService.find(hql,searchForm, page, rows);
//省略。。。
}
@Override
public String getCompleSearchHQL(ComplexSearchForm searchForm) {
String hql="from Book as book where 1=1 ";//前台已做验证,不能提交空的查询条件
if(searchForm.getName()!=null){
hql+="and book.BookName like :Name ";
}
if(searchForm.getAuthor()!=null){
if(searchForm.getName()!=null){
hql+=searchForm.getLogic1()+"book.Author like :Author ";
}else{
hql+="and book.Author like :Author ";
}
}
if(searchForm.getSeries()!=null){
if(searchForm.getAuthor()!=null){
hql+=searchForm.getLogic2()+"book.Series like :Series ";
}else{
if(searchForm.getName()!=null){
hql+=searchForm.getLogic1()+"book.Series like :Series ";
}else{
hql+="and book.Series like :Series ";
}
}
}
return hql;
}
现在就是怎么使用setProperties方法 和通配符 %