Mybatis-Plus 关闭驼峰式命名转换为下划线

SpringBoot 项目中,实体 User 属性 userAccount,数据库字段也为 userAccount,后端报错

### Error updating database.  Cause: java.sql.SQLSyntaxErrorException: Unknown column 'user_account' in 'field list'
### The error may exist in site/dopplerxd/backend/mapper/UserMapper.java (best guess)
### The error may involve site.dopplerxd.backend.mapper.UserMapper.insert-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO user  ( id, user_account, user_password )  VALUES (  ?, ?, ?  )
### Cause: java.sql.SQLSyntaxErrorException: Unknown column 'user_account' in 'field list'

原因是 Mybatis-Plus 自动将驼峰式命名转换为下划线了,解决方法有二:

  1. 在配置文件中设置关闭即可
mybatis-plus:
  configuration:
    map-underscore-to-camel-case: false
  1. 通过 @TableField 注释来设置属性对应的字段名
@Data
public class UserInfo {
    @TableId(value = "id")
    private Integer id;
    @TableField(value = "userAccount")
    private String userAccount;
}
本文采用 CC BY-NC-SA 4.0 协议许可
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇