I'm define a class "User.class", and it have property "birth" with a java type "java.time.LocalDate"。
And I'm write the mapping XML file "IUserMapper.xml" like this below:
<mapper namespace="*.entity.mapper.IUserMapper" >
<resultMap type="User" id="userResultMap" >
<id property="id" column="uid" jdbcType="BIGINT" javaType="long" />
<result property="name" column="name" jdbcType="VARCHAR" javaType="string" />
<result property="password" column="password" jdbcType="VARCHAR" javaType="string" />
<result property="gender" column="gender" typeHandler="*.util.typehandler.GenderEnumTypeHandler" />
<result property="birth" column="birth" jdbcType="DATE" javaType="localdate" />
</resultMap>
......
</mapper>
Obviously, javaType="localdate" is wrong! Because the 'localdate' java type alias do not defined in TypeAliasRegistry.class.
So, i defined it by myself in MyBatis-Config.xml at the element node <typeAliases>
...
<typeAlias type="java.time.LocalDate" alias="localdate" />
<typeAlias type="java.time.LocalDateTime" alias="localdatetime" />
...
</typeAliases>
and now it works fine. But this way still not work for java type alias like 'localdate[]', 'localdatetime[]'.
so guys, why do not consider adding some new java type alias, like 'localdate', 'localdate[]', 'localdatetime', 'localdatetime[]' in TypeAliasRegistry.class?
Comment From: harawata
Hello @sun-777 ,
In most cases, you don't have to specify javaType explicitly because MyBatis figure it out from the class definition, so it probably is not useful very much.
Comment From: sun-777
@harawata ^_^ Yeah, I know that, and your opinion is right. I think adding those new type alias have nothing wrong, even making mybatis more better. right? So, you guys could seriously consider this suggestion. For programmers with OCD, more friendly. [:/laugh]
Comment From: harawata
Let's close this. :)
You may be aware, but you can register type aliases by yourself if you have to type these class FQN frequently for some reason.
https://mybatis.org/mybatis-3/configuration.html#typeAliases
And this way, you can register even shorter alias like ldh for LocalDateTime, so I think it's better. 😉