1 public List<PostVo> queryByKeyWord(String keyWord){ 2 BeanListHandler<PostVo> bh=new BeanListHandler<PostVo>(PostVo.class); 3 List<PostVo> list=jt.query("select * from post where title like '%?%' or author like '%?%' or content like '%?%' order by noteid ", bh,keyWord,keyWord,keyWord); 5 jt.close(); 6 return list;
}
死活查不到数据,原因是SQL代码拼接总会有点问题,记得以前做PHP时也出现过这种情况。
改成下面的就可以了。
1 public List<PostVo> queryByKeyWord(String keyWord){ 2 BeanListHandler<PostVo> bh=new BeanListHandler<PostVo>(PostVo.class); 3 String param="%"+keyWord+"%"; 4 List<PostVo> list=jt.query("select * from post where title like ? or author like ? or content like ? order by noteid ", bh,param,param,param); 5 jt.close(); 6 return list;