MyBatis-Plus|MyBatis-Plus SQLServer 分页查询

【MyBatis-Plus|MyBatis-Plus SQLServer 分页查询】SpringBoot 演示项目:
POM

com.baomidou mybatis-plus-boot-starter 3.4.3.4 com.microsoft.sqlserver sqljdbc4 4.0

Config
# DataSource Config spring: datasource: driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver url: jdbc:sqlserver://127.0.0.1:1433; databaseName=my_db username: sa password: 123456# Print SQL mybatis-plus: configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

Model
@Data @TableName("user") public class User { private Long id; private String name; }

Mapper
@Service public interface UserMapper extends BaseMapper { }

Test
@SpringBootTest public class LessonTest {@Autowired private UserMapper userMapper; /** * 测试分页获取用户 */ @Test public void testPageUsers() { // 第 1 页,每页 10 条记录 Page page = new Page<>(1, 10); // 设置查询条件:按照用户名排序 QueryWrapper wrapper = new QueryWrapper<>(); wrapper.orderByAsc("Name"); // 分页获取用户 Page users = userMapper.selectPage(page, wrapper); // 验证用户数应为 10 assert users.size() == 10; }}

    推荐阅读