mybatis-plus返回map自动转驼峰配置

(一)
mybatis-plus自带map下划线转驼峰配置类 
我们只需要在yml中配置一下object-wrapper-factory指定MybatisMapWrapperFactory就可以了
mybatis-plus:  mapper-locations: classpath:mapper/*Mapper.xml
   configuration:    call-setters-on-nulls: true
     map-underscore-to-camel-case: true
     object-wrapper-factory: com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory
 @Component
    @ConfigurationPropertiesBinding
    public class ObjectWrapperFactoryConverter implements Converter<String,ObjectWrapperFactory> {
        @Override    
        public ObjectWrapperFactory convert(String source) {
            try {
                return (ObjectWrapperFactory) Class.forName(source).newInstance();
            } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
        }
    }

 

 

(二)

@Bean
    public ConfigurationCustomizer mybatisConfigurationCustomizer(){
        return configuration -> configuration.setObjectWrapperFactory(new MybatisMapWrapperFactory());
    }

 

 

 

 
posted @ 2022-07-21 08:45    阅读(1033)  评论(0编辑  收藏  举报