Mapper sql語句字段和實體類屬性名字有什么關(guān)系
背景:
1.在數(shù)據(jù)庫中有一個通知表
可以看到其中的
- gmt_create、
- notifier_name、
- outer_title
這三個字段是有下劃線的
2.這張表對應(yīng)的實體類為
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);
結(jié)論:在進(jìn)行占位時#{}中的內(nèi)容應(yīng)為gmtCreate
寫的時候留心下,寫成gmt_create可能會報錯
There is no getter for property named 'gmt_create' in 'class com.example.com
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
mysql load data infile 的用法(40w數(shù)據(jù) 用了
測試數(shù)據(jù)的時候,生成txt文件應(yīng)該快點,再用這種方式導(dǎo)入到mysql 速度上快點,40w數(shù)據(jù) 用了3-5秒導(dǎo)進(jìn)mysql2013-01-01mysql分組后合并顯示一個字段的多條數(shù)據(jù)方式
這篇文章主要介紹了mysql分組后合并顯示一個字段的多條數(shù)據(jù)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-01-01DBeaver如何實現(xiàn)導(dǎo)入excel中的大量數(shù)據(jù)
使用DBeaver導(dǎo)入Excel數(shù)據(jù)需先將文件轉(zhuǎn)換為CSV格式,詳細(xì)步驟包括:將Excel文件另存為CSV,確保列名與數(shù)據(jù)庫表字段對應(yīng),然后在DBeaver中創(chuàng)建表和導(dǎo)入CSV文件,注意選擇正確的編碼格式以防中文亂碼2024-10-10