zoukankan      html  css  js  c++  java
  • Springboot使用PageHelper(需要解决依赖冲突)

    1、导入相关依赖PageHelper自带了mybatis、mybatis-spring,不排除会报错

    <!-- pagehelper分页插件依赖 -->
    <dependency>
        <groupId>com.github.pagehelper</groupId>
        <artifactId>pagehelper-spring-boot-starter</artifactId>
        <version>1.2.10</version>
        <exclusions>
            <exclusion>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis-spring</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    2、在application.yml 配置文件中配置指定数据库

    #pagehelper配置
    pagehelper:
      helper-dialect: mysql

    其他相关配置:https://www.cnblogs.com/mengw/p/11673637.html

    或者使用配置类

    3、使用Pagehelper多条件分页

    条件类:

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public class HouseQueryInfo implements Serializable{
        private static final long serialVersionUID = 1034989291292817460L;
        //private int pageIndex;//当前页码(页面传递)
        //private int pageSize;//页容量(后台设置)
        private String title;
        private String price_on;
        private String price_down;
        private String street_id;
        private String type_id;
        private String floorage_on;
        private String floorage_down;
        
    }

    service层接口:

    public interface IHouseService extends IService<House>{
        //根据条件查询所有房屋信息,分页显示
        List<House> findAllHouse(HouseQueryInfo houseInfo) throws Exception;
    
        //使用pagehelper分页查询
        public PageInfo<House> findBookPage(Integer pageIndex,Integer pageSize,HouseQueryInfo houseInfo) throws Exception;
    }

    serviceimpl实现类:

    @Service
    public class HouseServiceImpl extends ServiceImpl<IHouseMapper, House>  implements IHouseService {
        @Autowired
        private IHouseMapper houseMapper;
        //根据条件查询所有房屋信息,分页显示
        @Override
        public List<House> findAllHouse(HouseQueryInfo houseInfo) throws Exception {
            return houseMapper.findAllHouse(houseInfo);
        }
       //根据所有信息进行分页
        @Override
        public PageInfo<House> findBookPage(Integer pageIndex,Integer pageSize,HouseQueryInfo houseInfo) throws Exception {
            PageHelper.startPage(pageIndex,pageSize);
            PageInfo<House> pageinfo = new PageInfo<>(houseMapper.findAllHouse(houseInfo));
            return pageinfo;
        }

    controller层:

    PageInfo<House> pageInfo = houseService.findBookPage(houseInfoVo.getPageIndex(),3,houseInfo);
    // 将租房信息存入model中
     model.addAttribute("pageInfo", pageInfo);

    页面数据的展示:

    <TR th:each="house:${pageInfo.getList()}">
          <TD class=house-thumb><span>
        <img th:src="${house.photopath != null} ? |/img/${house.photopath}| :'../images/thumb_house.gif' " width="100" height="75"</span></TD>
          <TD>
              <DL>
                   <DT>
                      <A href="#" th:text="${house.title}"></A>
                   </DT>
                        <DD>
                           <span th:text="${house.streets.name}"/>
                           <span th:text="${house.streets.district.name}"/>
                           <span th:text="${house.floorage}"/> 平米<BR>联系方式:<span th:text="${house.contact}"/> 
                         </DD>
              </DL>
           </TD>
        <TD class=house-type><span th:text="${house.typess.name}"/></TD>
        <TD class=house-price><SPAN th:text="${house.price}"></SPAN>元/月</TD>
    </TR>
  • 相关阅读:
    php工作笔记5-css定位
    php工作笔记4-mysql笔记1
    php工作笔记3-php基础加强
    php工作笔记2-php编码效率
    php工作笔记1-数组常用方法总结,二维数组的去重,上传图片到oss服务器
    android浏览器 源码共享
    违章查询源码分享
    CENTOS 6.5 配置YUM安装NGINX
    Linux下安装Oracle11g服务器
    ARCGIS SDE空间化处理
  • 原文地址:https://www.cnblogs.com/64Byte/p/13269576.html
Copyright © 2011-2022 走看看