spring mybatis返回的Map的key用驼峰转换
这是是用了mybatis-plus的情况,只用在代码里加入以下类即可:
package com.xx.config; import com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory; import org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory; import org.springframework.boot.context.properties.ConfigurationPropertiesBinding; import org.springframework.context.annotation.Bean; import org.springframework.core.convert.converter.Converter; import org.springframework.stereotype.Component; @Component @ConfigurationPropertiesBinding public class ConfigurationCustomizer 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 com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer mybatisConfigurationCustomizer(){ return configuration -> configuration.setObjectWrapperFactory(new MybatisMapWrapperFactory()); } }
相关阅读
评论:
↓ 广告开始-头部带绿为生活 ↓
↑ 广告结束-尾部支持多点击 ↑