mybatis 3.5.1中对于java.time包LocalDateTime,LocalDate,LocalTime类型的处理与mybatis 3.5.0有所不同...
时间: 2023-06-20 18:07:25 浏览: 83
是的,MyBatis 3.5.1中对Java 8中的新日期时间API(java.time包)进行了更新和改进。这些改进包括:
- 加入对`LocalDateTime`、`LocalDate`和`LocalTime`类型的支持。
- 加入对`java.sql.Timestamp`、`java.sql.Date`和`java.sql.Time`类型相应的转换支持。
- 加入对`java.util.Date`类型的支持,它现在被转换为`java.time.LocalDateTime`类型。
此外,MyBatis 3.5.1还更新了内部的`org.apache.ibatis.type.LocalDateTimeTypeHandler`,以更好地支持JDBC驱动程序的行为。
需要注意的是,如果您的应用程序在使用MyBatis 3.5.0之前已经使用了这些类型,请谨慎升级到MyBatis 3.5.1,因为MyBatis 3.5.1中的类型处理可能与您的应用程序不兼容。
相关问题
mybatis 中java.util.Date and java.lang.String 报错
在MyBatis中,当你在查询条件中将`java.util.Date`类型的属性与`java.lang.String`类型的属性进行比较时,可能会出现报错信息"invalid comparison: java.util.Date and java.lang.String"。这是因为在比较过程中,MyBatis无法将`java.util.Date`类型的属性与`java.lang.String`类型的属性进行正确的比较。
为了解决这个问题,你可以使用MyBatis提供的类型处理器来处理`java.util.Date`类型的属性。类型处理器可以将`java.util.Date`类型的属性转换为数据库中的日期类型,以便正确比较。
以下是一个示例,展示了如何在MyBatis中使用类型处理器来解决`java.util.Date`和`java.lang.String`比较的问题:
1. 首先,在你的MyBatis配置文件中,添加类型处理器的配置:
```xml
<typeHandlers>
<typeHandler handler="org.apache.ibatis.type.DateTypeHandler" />
</typeHandlers>
```
2. 然后,在你的Mapper接口中,将`java.util.Date`类型的属性与`java.lang.String`类型的属性进行比较:
```xml
<select id="selectByDateAndString" parameterType="map" resultType="YourResultType">
SELECT * FROM your_table
WHERE date_column = #{dateProperty, jdbcType=DATE}
AND string_column = #{stringProperty, jdbcType=VARCHAR}
</select>
```
在上面的示例中,`date_column`是数据库表中的日期类型列,`string_column`是数据库表中的字符串类型列。`dateProperty`和`stringProperty`是你传入的参数,分别对应`java.util.Date`类型的属性和`java.lang.String`类型的属性。
通过使用类型处理器和正确设置jdbcType,你可以避免在MyBatis中比较`java.util.Date`和`java.lang.String`类型时出现报错。
pgsql 在mybatis中 resultType = java.util.Map
在MyBatis中,当使用PGSql数据库时,可以在resultType属性中设置java.util.Map来指定结果类型。这意味着查询结果将以Map的形式返回,其中键是列名,值是对应的列值。这种方式可以方便地处理动态列或者查询结果列名不确定的情况。请注意,使用Map作为结果类型可能会导致一些类型转换问题,因为数据库的列值可能是不同的数据类型。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)