第五步创建实体类
-
org.projectlombok -
lombok -
1.18.12 -
使用:
- @Data
- public class User {
- private Long id;
- private String name;
- private String password;
- private Integer age;
- private String tel;
- }
进行对比:
- //添加配置类,让springboot启动类扫描到这个类
- @Configuration
- public class MpConfig {
- @Bean
- public MybatisPlusInterceptor mpInterceptor(){
- //1.定义Mp拦截器
- MybatisPlusInterceptor mpInterceptor = new MybatisPlusInterceptor();
- //2.添加具体的拦截器
- mpInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
- return mpInterceptor;
- }
- }
测试代码:
- @Test
- void testGetByPage(){
- //IPage对象封装了分页操作相关的数据
- IPage page = new Page(2,3);
- userDao.selectPage(page,null);
- System.out.println("当前页码值:"+page.getCurrent());
- System.out.println("每页显示数:"+page.getSize());
- System.out.println("一共多少页:"+page.getPages());
- System.out.println("一共多少条数据:"+page.getTotal());
- System.out.println("数据:"+page.getRecords());
- }
- mybatis-plus:
- configuration:
- log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
结果:
- JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@706fe5c6] will not be managed by Spring
- ==> Preparing: SELECT COUNT(*) FROM user //原始sql语句
- ==> Parameters: //参数列表
- <== Columns: COUNT(*)
- <== Row: 4
- <== Total: 1
- ==> Preparing: SELECT id,name,password,age,tel FROM user LIMIT ?,? //追加的
- ==> Parameters: 3(Long), 3(Long)
- <== Columns: id, name, password, age, tel
- <== Row: 1713551068175183874, 程序员, mycobi, 12, 4006184000
- <== Total: 1
- Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@444cc791]