mysql 字段 下划线和实体类_Mapper sql语句字段和实体类属性名字有什么关系

背景:

1.在数据库中有一个通知表

89c6208ec871babf47ef8eeb55104684.png

可以看到其中的

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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

本文标题: Mapper sql语句字段和实体类属性名字有什么关系

本文地址: http://www.cppcns.com/shujuku/mysql/362673.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值