背景:
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