Mapper sql語句欄位和實體類屬性名字有什麼關係
阿新 • • 發佈:2020-11-11
背景:
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
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。