MyBatisPlus插件的学习2

自定义sql和分页的使用:

1. yml配置
mybatis-plus:
  mapper-locations:
  - com/example/demo/mapper/*
2. userMapper接口定义方法
List<Map<String, Object>> selectByTwo(@Param(Constants.WRAPPER) Wrapper<User> wrapper);
3. 定义mapper.xml文件
SELECT m.username,u.leave,u.money
FROM mp_user m JOIN user_info u ON m.id = u.uid ${ew.customSqlSegment}  
PS(customSqlSegment属性拼接了完整的 where语句 。注解修饰的属性需要自己添加别名)
1. 分页需要配置插件
@Configuration
public class PagePlugin {
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }
}
2. 分页类Page(current,size,boolean) 
Page<User> page = new Page<>(0, 3,false);
        IPage<User> Plist = userMapper.selectPage(page, query);
当boolean为false, 意味着count等属性不进行查询.
3. 也可以自定义分页方法
IPage<User> selectUserPage(Page<User> page,@Param(Constants.WRAPPER) Wrapper<User> wrapper);

猜你喜欢

转载自www.cnblogs.com/zkfly/p/11616422.html