spring boot项目中mybatis下划线转驼峰配置
一、
需要新建配置包config,在配置包里面新建配置类MyBatisConfig,在配置类中进行设置。
自定义MyBatis的配置规则;给容器中添加一个ConfigurationCustomizer;
1 @org.springframework.context.annotation.Configuration 2 public class MyBatisConfig { 3 4 @Bean 5 public ConfigurationCustomizer configurationCustomizer(){ 6 return new ConfigurationCustomizer(){ 7 8 @Override 9 public void customize(Configuration configuration) { 10 configuration.setMapUnderscoreToCamelCase(true); 11 } 12 }; 13 } 14 }
二、配置文件配置
1 在这里插入代码片#下划线转驼峰 2 mybatis.configuration.map-underscore-to-camel-case=true
三、少量字段可直接在dao层转换
1 @Select("select * from table") 2 @Results({ 3 @Result(column = "",property ="") 4 }) 5 List<Table>selectAll();

浙公网安备 33010602011771号