MyBatis 您所在的位置:网站首页 mybatisplus分页插件查询 MyBatis

MyBatis

2023-09-11 04:11| 来源: 网络整理| 查看: 265

请求接口 @GetMapping("/page") public R getOauthClientDetailsPage(Page page, OauthClientDetails sysOauthClientDetails) { return R.ok(oauthClientDetailsService.page(page, Wrappers.query(sysOauthClientDetails))); }

调用 Iservice的 page接口实现分页查询,

/** * 翻页查询 * * @param page 翻页对象 * @param queryWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper} */ default E page(E page, Wrapper queryWrapper) { return getBaseMapper().selectPage(page, queryWrapper); }

接口一直没有数据,status 200,

{code: 0, msg: null,…} code: 0 data: {records: 0, total: 0,…} msg: null 解决思路:

第一步查看sql语句 在 bootstrap.yml 配置文件中添加 日志实现,让mybatis-plus打印sql语句

#mybatis-plus配置控制台打印完整带参数SQL语句 mybatis-plus: configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

第二步,分析sql语句 分页查询语句有两个,

select count(*) from … 查询总记录数select … limit ? 分页查询

分析上述sql发现 我的总记录数 一直是0 ,所以第二个sql都没有执行

但是数据库明明有记录啊。 查看查询条件,多了一个 where createTime ? 赋值为 2021年4月27日17:02:49 数据库的记录和这些都不匹配 所以查看实体类createTime属性 发现指定死了 时间, private LocalDateTime createTime=now(); 所以查不到,这里去掉这个 now()。就可以了

端点也打不进去,最后排除为mapper 文件映射 实体。这个是错误的实体类型

/** * 创建时间 */ @ApiModelProperty(value = "创建时间") private LocalDateTime createTime=now(); /** * The client is trusted or not. If it is trust, will skip approve step * default false. * 客户端是否可信任,默认false */ @ApiModelProperty(value = "客户端是否可信任,默认false") private Boolean trusted ; /** * client info archived * 客户端是否已删除 */ @ApiModelProperty(value = "客户端是否已删除") private Boolean archived ;

检查数据库发现字段对应为 tinyint 所以对应 字段需要改为Integer

/** * 是否自动放行 */ @ApiModelProperty(value = "是否自动放行") private String autoapprove; /** * The client is trusted or not. If it is trust, will skip approve step * default false. * 客户端是否可信任,默认false */ @ApiModelProperty(value = "客户端是否可信任,默认false") private Integer trusted ;


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有