1.操作步骤
(一)在config文件下创建MybatisPlusConfig.class文件用来添加分页插件
/**
* @ClassName MybatisPlusConfig
* @Description: //TODO mybatis-plus添加分页插件
* @Author wyq
* @Date 2021/8/30 12:38
*/
@Configuration
@MapperScan("com.qcby.rbacwyq.dao")
public class MybatisPlusConfig {
// 最新版
@Bean // <bean id=""/>
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
}
(二)调整dao层
public interface DemoDao extends BaseMapper<Role> {
List<Role> list();
}
(三)调整service层
public interface DemoService extends IService<Role> {
List<Role> list(int pageNo, int pageSize);
}
(四)实现层 添加
@Service
public class DemoServiceImpl extends ServiceImpl<DemoDao, Role> implements DemoService {
@Resource
private DemoDao demoDao;
@Override
public List<Role> list(int pageNo, int pageSize) {
List<Role> roleList=demoDao.list();
return roleList;
}
}
(五)controller层测试
@RestController
@RequestMapping("demo")
public class DemoController {
@Resource
private DemoService demoService;
@RequestMapping("listAllPage")
public IPage<Role> listAllPage(int pageNo, int pageSize){
IPage<Role> page=new Page<>(pageNo,pageSize);
return demoService.page(page);
}
}
2.测试分页结果