在Mapper中sql語句字段與實體類屬性名字之間的關系


背景:

1.在數據庫中有一個通知表

 

 可以看到其中的

gmt_create、
notifier_name、
outer_title
這三個字段是有下划線的

2.這張表對應的實體類為
public class Notification {
private Long id;
private Long notifier;
private Long receiver;
private Long outerId;
private Integer type;
private Long gmtCreate;
private Integer status;
private String notifierName;
private String outerTitle;
}

在寫實際java代碼命名采用駝峰命名

注意application.properties是否開啟了駝峰映射
#駝峰映射
mybatis.configuration.map-underscore-to-camel-case=true


3.在Mapper中有一個插入語句
//0.插入一條通知
@Insert("insert into questions (title,description,gmt_create,gmt_modified,creator,tag) values (#{title},#{description},#{gmtCreate},#{gmtModified},#{creator},#{tag})")
void createQuestion(Question question);


結論:在進行占位時#{}中的內容應為gmtCreate

寫的時候留心下,寫成gmt_create可能會報錯
There is no getter for property named 'gmt_create' in 'class com.example.com



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM