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
