[英]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.