SSM+layui分页(了解98%)

第一步:配置pom.xml

<dependency>
      <groupId>com.github.pagehelper</groupId>
      <artifactId>pagehelper</artifactId>
      <version>5.1.10</version>
    </dependency>

第二步:配置Spring_servlet.xml

<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">标签中添加:

<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageInterceptor">
<property name="properties">
<value></value>
</property>
</bean>
</array>
</property>

 第三步:配置Service接口

 JsonData allShop(int limit,int page); 

 第四步:配置Service实体类,也就是ServiceImpl

只需要一个全查询操作就可以,无需多添加

@Override
    public JsonData allShop(int limit,int page) {
        PageHelper.startPage(page,limit);
        List<Shopinfo>  shopinfos=shopinfoMapper.allShop(limit, page);
        PageInfo<Shopinfo> pageInfo=new PageInfo<>(shopinfos);
        return JsonData.buildSuccess(pageInfo,"success");
    }

第五步:配置Mapper接口

 List<Shopinfo> allShop(int limit,int page);

第六步:配置Controller

@RequestMapping("/allShop")
    @ResponseBody
    public String allShop(int limit,int page){
        JsonData allShop=shopinfoService.allShop(limit,page);
        return JSON.toJSONString(allShop);
    }

第七步:在Layui框架中自己设定的js文件中的全查询操作“]]”之后添加

,parseData:function(rs){//数据格式解析
            console.log("rs===="+rs.toString()+"---"+rs.data.total+"---"+rs.data.list+"---"+rs.msg)
            return { // 里面的每一个值必须与传递的json 数据对应
                "code":rs.code,    //返回状态码200
                "msg":rs.msg,    // 消息
                "count":rs.data.total,    //总条目
                "data":rs.data.list    //具体内容
            }
        }

记得在添加全查询路径的下一项添加

 ,page:true  //开启分页

--------------------------------------------------------------------------------------------------------------------------感谢到访!期待您的下次光临!

原文地址:https://www.cnblogs.com/varchar-pig/p/14244088.html