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 |
/**
* 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