Mybatis_Plus分页插件的运用
mybatis-plus官网:https://mybatis.plus/
一. 引入POM依赖
<!--MybatisPlus-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.2</version>
</dependency>
<!--pageHelp 分页插件-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.3.1</version>
</dependency>
二. Controller
在@GetMapping("/findAll")
public List<UserVo> findAll() {
UserVo vo = new UserVo();
//增加查询条件
vo.setId(6);
vo.setMingzi("周");
List<UserVo> all = userService.findAll(1,10,vo);
return all;
}
三. Service
@Override
public List<UserVo> findAll(int pageNum, int pageSize,UserVo vo) {
// 创建分页对象
Page<UserVo> page = new Page<>(pageNum, pageSize);
List<UserVo> userList = userMapper.selectAllData(page,vo);
return userList;
}
四. Mapper
List<UserVo> selectAllData(Page page,@Param("vo")UserVo vo);
五. UserMapper.xml
<select id="selectAllData" resultType="com.zhoupan.test_zp.user.vo.UserVo">
select * from user where 1 = 1
<if test="vo.id!=null and vo.id !=''">
and id = #{vo.id}
</if>
and mingzi like concat("%",#{vo.mingzi},"%")
</select>