Springboot使用PageHelper(需要解决依赖冲突)

2021-04-23 14:29

阅读:618

标签:zab   inter   wired   rtp   width   span   div   height   根据   

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


dependency>
    groupId>com.github.pagehelpergroupId>
    artifactId>pagehelper-spring-boot-starterartifactId>
    version>1.2.10version>
    exclusions>
        exclusion>
            groupId>org.mybatisgroupId>
            artifactId>mybatisartifactId>
        exclusion>
        exclusion>
            groupId>org.mybatisgroupId>
            artifactId>mybatis-springartifactId>
        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{
    //根据条件查询所有房屋信息,分页显示
    List findAllHouse(HouseQueryInfo houseInfo) throws Exception;

    //使用pagehelper分页查询
    public PageInfo findBookPage(Integer pageIndex,Integer pageSize,HouseQueryInfo houseInfo) throws Exception;
}

serviceimpl实现类:

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

controller层:

PageInfo 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>

 

Springboot使用PageHelper(需要解决依赖冲突)

标签:zab   inter   wired   rtp   width   span   div   height   根据   

原文地址:https://www.cnblogs.com/64Byte/p/13269576.html


评论


亲,登录后才可以留言!