Springmvc使用PageHelper分页插件

2021-04-23 18:28

阅读:568

标签:使用   session   ISE   factor   gen   override   容量   图片   color   

1、导入相关依赖


dependency>
        groupId>com.github.pagehelpergroupId>
        artifactId>pagehelperartifactId>
        version>5.0.0version>
dependency>

2、在applicationContext.xml配置文件中增加PageHelper的定义

bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
        property name="dataSource" ref="dataSource"/>
        property name="configLocation" value="classpath:mybatis-config.xml"/>
        property name="mapperLocations" value="classpath*:mapper/*Mapper.xml"/>
        property name="typeAliasesPackage" value="com.zl.newHouse.entity"/>
        
        property name="globalConfig" ref="globalConfig"/>
        
        property name="plugins">
            array>
                bean class="com.github.pagehelper.PageInterceptor">
                    property name="properties">
                        props>
                            prop key="helperDialect">oracleprop> //如果是mysql只需要更改为mysql即可
                            prop key="reasonable">trueprop>
                        props>
                    property>
                bean>
            array>
        property>
    bean>

测试:

条件类:

技术图片技术图片
@Data
@AllArgsConstructor
@NoArgsConstructor
public class HouseQueryInfo {
    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;
    
}
View Code

编写一个接口:

public interface  IHouseService extends IService{
    
    //根据条件查询所有房屋信息,分页显示  findAllHouse自己编写多表多条件查询的sql语句
    List findAllHouse(HouseQueryInfo houseInfo) throws Exception;

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

编写一个接口的实现类:

//根据条件查询所有房屋信息,分页显示
@Override
public List findAllHouse(HouseQueryInfo houseInfo) throws Exception {
    return houseMapper.findAllHouse(houseInfo);
}
//根据查询出来的数据分页显示
@Override
public PageInfo findBookPage(HouseQueryInfo houseInfo) throws Exception {
        PageHelper.startPage(houseInfo.getPageIndex(),houseInfo.getPageSize());
    List bookHouses = houseMapper.findAllHouse(houseInfo);
    PageInfo pageinfo = new PageInfo(bookHouses);
    return pageinfo;
}

测试数据:

@Test
public void testpage() throws  Exception{
    HouseQueryInfo houseInfo = new HouseQueryInfo(1,3,"", "", "", "", "", "", "");
    PageInfo pageInfo = houseService.findBookPage(houseInfo);
    System.out.println("总数量" + pageInfo.getTotal());
    System.out.println("当前页查询记录数" + pageInfo.getList().size());
    System.out.println("当前页码" + pageInfo.getPageNum());
    System.out.println("每页显示数量" + pageInfo.getPageSize());
    System.out.println("总页" + pageInfo.getPages());
    System.out.println("当前页查询记录" + pageInfo.getList());
}

 

Springmvc使用PageHelper分页插件

标签:使用   session   ISE   factor   gen   override   容量   图片   color   

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


评论


亲,登录后才可以留言!