繁体   English   中英

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

[英]springboot map-underscore-to-camel-case invalid

我的春季版本是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

问题已解决,计划如下

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());
        }
    };
}
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM