springboot map-underscore-to-camel-case无效

时间:2018-04-12 16:57:37

标签: java mybatis spring-mybatis

我的春季版本是1.5.2,spring-mybatis-start版本是1.3.2, 我在属性中设置了mybatis.configuration.map-underscore-to-camel-case=true。 但我返回的MAP未转换为名为

Camel

这是我的配置

mybatis.configuration.map-underscore-to-camel-case=true

1 个答案:

答案 0 :(得分:0)

问题已解决,计划如下

public class CustomWrapper extends MapWrapper{

public CustomWrapper(MetaObject metaObject, Map<String, Object> map) {
    super(metaObject, map);
}

// useCamelCaseMapping is map-underscore-to-camel-case field
@Override
public String findProperty(String name, boolean useCamelCaseMapping) {
    if(useCamelCaseMapping){
        return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL,name);
    }
    return name;
}
}

public class MapWrapperFactory implements ObjectWrapperFactory {

@Override
public boolean hasWrapperFor(Object object) {
    return object != null && object instanceof Map;
}

@Override
public ObjectWrapper getWrapperFor(MetaObject metaObject, Object object) {
    return new CustomWrapper(metaObject,(Map)object);
}
}

@Configuration
public class MybatisConfig {

@Bean
public ConfigurationCustomizer mybatisConfigurationCustomizer(){
    return new ConfigurationCustomizer() {
        @Override
        public void customize(org.apache.ibatis.session.Configuration configuration) {
            configuration.setObjectWrapperFactory(new MapWrapperFactory());
        }
    };
}
}