mapper.xml页面
sql传入map,需要用${},不能用#{}
<select id="findAllByCountName" parameterType="java.util.Map" resultType="bean.ChuHuoDan" >
<!-- SELECT * FROM chuhuodan WHERE siji LIKE '%张%' ORDER BY createtime DESC limit 0,5; -->
SELECT * FROM chuhuodan WHERE siji LIKE ${moHuName} ORDER BY createtime DESC limit ${pageNum},${pageSize}
</select>
serviceImpl层
@Override
public List<ChuHuoDan> findAllByCountName(String moHuName, Integer pageNum, Integer pageSize) {
moHuName="'%"+moHuName+"%'";
System.out.println (moHuName);
map.put ( "moHuName",moHuName );
map.put ( "pageNum" ,pageNum);
map.put ( "pageSize",pageSize );
return chuHuoDanMapper.findAllByCountName(map);
}
Controller层
@RequestMapping("findChuHuoDanByCountName")
public String findChuHuoDanByCountName(Model model, String moHuName,
@RequestParam(value = "pageNum" ,defaultValue = "1") Integer pageNum,
@RequestParam(value = "pageSize",defaultValue ="5")Integer pageSize){
if (pageNum==0){
pageNum=1;
}
count = chuHuoDanService.findCount ();
limitPage = (int)Math.ceil ( count / pageSize );
allCH = chuHuoDanService.findAllByCountName (moHuName,(pageNum - 1) * pageSize, pageSize );
model.addAttribute ( "moHuName",moHuName );
model.addAttribute ( "list",allCH);
model.addAttribute ("pageNum",pageNum);
model.addAttribute ("firstPage",1);
model.addAttribute ("lastPage",limitPage);
return "show.jsp";
}