mybatis-plus查询数据数量正确,但每条数据都为null
java bean与表字段完全对应(名字相同)
@data @allargsconstructor @noargsconstructor public class auth { @tableid(type = idtype.auto) private integer auth_id; private string auth_name; }
serviceimpl
@override public list<auth> getauth() { return authmapper.selectlist(null); }
查询结果
[null,null,null,null,null]
查询的数量正确但是,每条数据都是null
分析:每一条数据都没有与数据库的字段匹配
解决:关闭驼峰映射
mybatis-plus: mapper-locations: classpath:/mapper/*.xml type-aliases-package: com.lixianhe.pojo configuration: log-impl: org.apache.ibatis.logging.stdout.stdoutimpl # 关闭驼峰映射 map-underscore-to-camel-case: false
这是因为mybatis默认开启驼峰命名法,即按规则数据表中的lastname字段应对应实体类中的last_name属性,而实体类中的lastname属性应对应数据表中的last_name字段。
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论