安装:
pom文件
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.6</version>
<exclusions>
<exclusion>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</exclusion>
</exclusions>
</dependency>
传统使用:
pagebean 是封装类,一个是总数,一个是数据
插件
/**
* 分页查询
*/
@GetMapping("/selectPage")
public Result selectPage(Activity activity,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) {
PageInfo<Activity> page = activityService.selectPage(activity, pageNum, pageSize);
return Result.success(page);
}
/**
* 分页查询
*/
public PageInfo<Activity> selectPage(Activity activity, Integer pageNum, Integer pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<Activity> list = activityMapper.selectAll(activity);
return PageInfo.of(list);
}
<select id="selectAll" resultType="com.example.entity.Activity">
select
<include refid="Base_Column_List" />
from activity
<where>
<if test="id != null"> and id = #{id}</if>
<if test="name != null"> and name like concat('%', #{name}, '%')</if>
<if test="descr != null"> and descr like concat('%', #{descr}, '%')</if>
<if test="start != null"> and start like concat('%', #{start}, '%')</if>
<if test="end != null"> and end like concat('%', #{end}, '%')</if>
<if test="form != null"> and form like concat('%', #{form}, '%')</if>
<if test="address != null"> and address like concat('%', #{address}, '%')</if>
<if test="host != null"> and host like concat('%', #{host}, '%')</if>
<if test="readCount != null"> and read_count = #{readCount}</if>
<if test="cover != null"> and cover = #{cover}</if>
</where>
order by id desc
</select>