mybatis tinyint 映射类型
时间: 2023-09-27 09:09:22 浏览: 192
mybatis 映射 生成
在使用Mybatis Generator生成代码时,默认情况下,MySQL数据库中的tinyint类型会映射为Java的Boolean类型。然而,有一些情况下我们可能需要将tinyint映射为Java的Byte类型。为了实现这个映射,可以使用自定义的类型解析器。在自定义类型解析器中,我们可以将数据库的TINYINT映射成Java的Integer类型。具体的做法是,在自定义的JavaTypeResolver中添加如下代码:
```java
public class CustomerJavaTypeResolver extends JavaTypeResolverDefaultImpl {
public CustomerJavaTypeResolver() {
super();
//将数据库的TINYINT映射成Integer类型
super.typeMap.put(Types.TINYINT, new JavaTypeResolverDefaultImpl.JdbcTypeInformation("TINYINT", new FullyQualifiedJavaType(Integer.class.getName())));
}
}
```
通过这种方式,我们可以将MySQL中的tinyint类型映射为Java的Integer类型。这样,在使用Mybatis Generator生成代码时,tinyint字段就会被映射为Java的Integer类型。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Mybaits-mybatis-generator数据库tinyint数据类型类型映射问题](https://blog.csdn.net/qq_19331985/article/details/104790644)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [解决Mybatis Generator 将tinyint映射为Byte和Boolean](https://blog.csdn.net/yu542771572/article/details/116607642)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文