mybatis-plus resultType映射map 转驼峰


mybatis-plus resultType映射map 转驼峰

 

resultType 为map的情况key不是驼峰
mapper
List<Map<String, String>> getUser(@Param("startDate") String startDate, @Param("endDate") String endDate);
1
xml
<select id="getUser" resultType="java.util.Map">
SELECT
su.user_name ,
su.real_name
FROM
sys_user sur
</select>

 

 

 


实际查询key非驼峰

修改key 驼峰
使用MybatisMapWrapperFactory 下划线转驼峰配置类

# mybatis-plus config
mybatis-plus:
configuration:
# 是否打印sql,dev使用,pro环境不开启
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# 是否开启驼峰
map-underscore-to-camel-case: true
# map 映射value为null的情况
call-setters-on-nulls: true

 

 

 

 

 

 

 


/**
* map类型key转驼峰
*
* @return {@link ConfigurationCustomizer}
*/
@Bean
public ConfigurationCustomizer mybatisConfigurationCustomizer() {
return configuration -> configuration.setObjectWrapperFactory(new MybatisMapWrapperFactory());
}
注意:配置后null值查询不出来,新增call-setters-on-nulls: true即可

最后的效果

 

 

 

配置添加
可参考:https://www.jb51.net/article/200757.htm

添加object-wrapper-factory: com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory

自定义Converter注入
@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);
}
}
}
原文链接:https://blog.csdn.net/weixin_44573207/article/details/117120568


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM