map在Sql中的传参 模糊查询limit分页

Posted dune.F

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了map在Sql中的传参 模糊查询limit分页相关的知识,希望对你有一定的参考价值。

jsp页面
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";
    }

 


以上是关于map在Sql中的传参 模糊查询limit分页的主要内容,如果未能解决你的问题,请参考以下文章

java mybatis 分页模糊查询页面怎么写

SQL分页查询

PHP中模糊查询后实现分页时,只显示第一页信息,之后的页面信息不显示,求类似问题解决方法最好有代码,谢

分页功能设计(解决数据重复问题)

NodeJS中Sql使用Like模糊查询时的问号(?)传参

mysql按条件分页查询的语句怎么写啊?