前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Be Extra Careful about Pitfalls of MyBatis-Plus 2.x

Be Extra Careful about Pitfalls of MyBatis-Plus 2.x

作者头像
^_^肥仔John
发布2021-08-18 17:20:40
2760
发布2021-08-18 17:20:40
举报
文章被收录于专栏:偏前端工程师的驿站

What an Unreliable Lad You Are @TableField

Mybatis-Plus introduces many powerful annotations for us to indicate the mapping between entity properties and table fields. It's a great coding experience working with those annotations and IService relevant helper class. However, it's actually not true in Mybatis-Plus 2.x. Why? @TableField in 3.x could replace ResultMap fully, even applied in customized Mapper select statement like the example below.

代码语言:javascript
复制
package com.john.model;

@TableName("user")
public class User {
    @TableId
    private String id;
    @TableField("user_name")
    private String userName;
}
代码语言:javascript
复制
<mapper>
  <select id="getUsers" resultType="com.john.model.User">
    select * from user
  </select>
</mapper>

Believe me gentles, 2.x would let you down definitely. @TableField is out of work in above situation. What we have to do is declare the relations by ResultMap, or keep the entity property name as the same as the table field which is case-sensitive.

代码语言:javascript
复制
<mapper>
  <select id="getUsers" resultType="com.john.model.User">
    select id
           , user_name as userName
    from user
  </select>
</mapper>

The Pain I've Suffered from Pagination Plugin

Pagination plugin is another effective helper, but there are many differences between 3.x and 2.x. Listed as below.

Conclusion

If this post could give you a favor, it's my pleasure ?

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021-08-13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • What an Unreliable Lad You Are @TableField
  • The Pain I've Suffered from Pagination Plugin
  • Conclusion
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档