Skip to content

Commit f71fe22

Browse files
authored
Update faq.md
1 parent 042e7be commit f71fe22

File tree

1 file changed

+5
-42
lines changed

1 file changed

+5
-42
lines changed

guide/faq.md

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -338,53 +338,16 @@ mybatis-plus:
338338
> Page 对象是继承 RowBounds,是 Mybatis 内置对象,无法在 mapper 里获取
339339
> 请使用自定义 Map/对象,或者通过@Param("page") int page,size 来传参
340340

341-
## 开启查询结果【下划线转驼峰】
342-
343-
> 该功能是 mybatis 原生自带,配置如下
344-
345-
Spring Bean 配置:
346-
347-
```java
348-
MybatisConfiguration configuration = new MybatisConfiguration();
349-
configuration.setMapUnderscoreToCamelCase(true);//开启下划线转驼峰
350-
//...其他配置,见上面的【配置jdbcTypeForNull=NULL】
351-
```
352-
353-
Spring Boot yml 配置:
354-
355-
```yaml
356-
mybatis-plus:
357-
configuration:
358-
map-underscore-to-camel-case: true
359-
```
360-
361341
## 如何使用:【Map下划线自动转驼峰】
362342

363343
指的是:`resultType="java.util.Map"`
364344

365-
- todo 注意事项待定,等待3.1.1版本发布后再写
366-
367-
- Java Config Bean 方式
345+
- spring boot
368346

369347
```java
370-
@Configuration
371-
@MapperScan("com.baomidou.mybatisplus.test.h2.entity.mapper")
372-
public class MybatisConfigMetaObjOptLockConfig {
373-
374-
@Bean("mybatisSqlSession")
375-
public SqlSessionFactory sqlSessionFactory(DataSource dataSource, ResourceLoader resourceLoader, GlobalConfiguration globalConfiguration) throws Exception {
376-
MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
377-
MybatisConfiguration configuration = new MybatisConfiguration();
378-
configuration.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
379-
configuration.setJdbcTypeForNull(JdbcType.NULL);
380-
//*注册Map 下划线转驼峰*
381-
configuration.setObjectWrapperFactory(new MybatisMapWrapperFactory());
382-
383-
sqlSessionFactory.setConfiguration(configuration);
384-
//...其他配置
385-
return sqlSessionFactory.getObject();
386-
}
387-
...
348+
@Bean
349+
public ConfigurationCustomizer configurationCustomizer() {
350+
return i -> i.setObjectWrapperFactory(new MybatisMapWrapperFactory());
388351
}
389352
```
390353

@@ -463,4 +426,4 @@ private Boolean status;
463426

464427
原因: dev-tools, 3.1.1+针对字段缓存,使用.class来作为key替换了原来的className, 而使用dev-tools会把.class使用不同的classLoader加载,导致可能出现找不到的情况
465428

466-
解决方案: 去掉dev-tools插件
429+
解决方案: 去掉dev-tools插件

0 commit comments

Comments
 (0)