您当前的位置: 首页 >  mybatis

梁云亮

暂无认证

  • 3浏览

    0关注

    1211博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

MyBatis中当实体类的属性名和表中的字段名不一致时的解决方案

梁云亮 发布时间:2021-07-24 09:21:23 ,浏览量:3

比如数据库字段create_time,对应实体类属性createTime

方案一:写SQL语句时起别名

示例代码:

select create_time createTime from xxxxx;
方案二:开启驼峰命名规则

MyBatis配置文件中:


SpringBoot的yml文件中:
mybatis.configuration.map-underscore-to-camel-case:=true
方案三:在Mapper映射文件中使用resultMap自定义映射规则

示例:


	

方案四:编写MyBatis配置类

示例:

@Configuration
public class MyBatisConfig {
    @Bean
    public ConfigurationCustomizer configurationCustomizer(){
        return new ConfigurationCustomizer() {
            @Override
            public void customize(Configuration configuration) {
                configuration.setMapUnderscoreToCamelCase(true);
            }
        };
    }
}
关注
打赏
1665409997
查看更多评论
立即登录/注册

微信扫码登录

0.0404s