共计 667 个字符,预计需要花费 2 分钟才能阅读完成。
增加依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.0</version>
</dependency>
在启动类编辑
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2));
return interceptor;
}
Mapper 层编写
IPage<User> getList(Page<Object> page);
xml 文件编写 SQL
<select id="getList" resultMap="getUserDate">
select * from user
<!-- select * from user 最初不能增加; 号 -->
</select>
Test 测试
@Test
void Test01(){Page<Object> page = new Page<>(0, 2);
List<User> records = userMapper.getList(page).getRecords();
records.forEach(item->System.out.println(item));
}
正文完
发表至: mybatis-plus
2021-08-29