背景:
1.在數(shù)據(jù)庫中有一個(gè)通知表
可以看到其中的
- gmt_create、
- notifier_name、
- outer_title
這三個(gè)字段是有下劃線的
2.這張表對(duì)應(yīng)的實(shí)體類為
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;
}
在寫實(shí)際java代碼命名采用駝峰命名
注意application.properties是否開啟了駝峰映射
#駝峰映射
mybatis.configuration.map-underscore-to-camel-case=true
3.在Mapper中有一個(gè)插入語句
//0.插入一條通知
@Insert("insert into questions (title,description,gmt_create,gmt_modified,creator,tag) values (#{title},#{description},#{gmtCreate},#{gmtModified},#{creator},#{tag})")
void createQuestion(Question question);
結(jié)論:在進(jìn)行占位時(shí)#{}中的內(nèi)容應(yīng)為gmtCreate
寫的時(shí)候留心下,寫成gmt_create可能會(huì)報(bào)錯(cuò)
There is no getter for property named 'gmt_create' in 'class com.example.com
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:- MyBatis直接執(zhí)行SQL的工具SqlMapper
- 詳解 MapperScannerConfigurer之sqlSessionFactory注入方式
- Mybatis中SqlMapper配置的擴(kuò)展與應(yīng)用詳細(xì)介紹(1)
- 使用XSD校驗(yàn)Mybatis的SqlMapper配置文件的方法(2)
- 使用XSD校驗(yàn)Mybatis的SqlMapper配置文件的方法(1)
- 詳解MyBatis的getMapper()接口、resultMap標(biāo)簽、Alias別名、 盡量提取sql列、動(dòng)態(tài)操作
- MyBatis MapperProvider MessageFormat拼接批量SQL語句執(zhí)行報(bào)錯(cuò)的原因分析及解決辦法