springboot配置处理mybatis带有下划线数据库字段无法映射实体,解决驼峰命名映射问题
1.问题
接口请求后查询发现返回的部分数据为null,都是大小写字段驼峰命名的为空
[{"id":1,"userName":null,"phone":"13126789145","province":"03","userAccount":null,"userPassword":null}]
2.代码文件配置
(1)数据库设计字段为:
create table DEMO_USER
(
id NUMBER(10) not null,
user_name VARCHAR2(100),
phone VARCHAR2(30),
province VARCHAR2(50),
user_account VARCHAR2(50),
user_password VARCHAR2(50)
)
(2)对应实体:
public class DemoUserEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* $column.comments
*/
private Integer id;
/**
* $column.comments
*/
private String userName;
/**
* $column.comments
*/
private String phone;
/**
* $column.comments
*/
private String province;
/**
* $column.comments
*/
private String userAccount;
/**
* $column.comments
*/
private String userPassword;
}
(3)springboot项目配置文件 application.properties
#mybatis的相关配置
#mybatis.config-locations=classpath:mybatis/mybatis-config.xml
#mapper配置文件
mybatis.mapper-locations=classpath:mapper/*.xml
#mybatis.type-aliases-package=com.beiluo.demo.entity
3.解决方案
添加配置如下
#开启驼峰命名 处理下划线映射到实体
#mybatis.configuration.map-underscore-to-camel-case=true
最后springboot项目配置文件 application.properties为
#mybatis的相关配置
#mybatis.config-locations=classpath:mybatis/mybatis-config.xml
#mapper配置文件
mybatis.mapper-locations=classpath:mapper/*.xml
#mybatis.type-aliases-package=com.beiluo.demo.entity
#开启驼峰命名 处理下划线映射到实体
mybatis.configuration.map-underscore-to-camel-case=true
查询后有数据
[{"id":1,"userName":"张三","phone":"13126789145","province":"03","userAccount":"zhangsan","userPassword":"zhangsan"}]
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现