Mybatis配置类型的别名

2022-07-14 10:38:13

为类型定义别名其实上就是就是为Java类型设置一个短的名字,从而减少类的全限定名的冗余。

自定义别名: 可以直接在在mybatis的配置文件中对实体类起一个别名,这样在mybatis的上下文中就可以引用该别名。

<!--定义别名--><typeAliases><typeAliastype="com.ly.pojo.User"alias="user"/></typeAliases>

通过包扫描的方式来定义别名:mybatis会在包名下搜索需要的JavaBean,其默认的别名就是实体类的类名(首首字母小写):

<!--定义别名--><typeAliases><!--使用包扫描的方式--><packagename="com.ly.pojo"/></typeAliases>

如果想要修改默认的别名:可以在实体类上添加注解@Alias:

@Alias("user")publicclassUser{...}

Java 类型内建的类型别名注:它们都是不区分大小写的

别名映射的类型
_bytebyte
_longlong
_shortshort
_intint
_integerint
_doubledouble
_floatfloat
_booleanboolean
别名映射的类型
stringString
byteByte
longLong
shortShort
intInteger
integerInteger
doubleDouble
floatFloat
booleanBoolean
dateDate
decimalBigDecimal
bigdecimalBigDecimal
objectObject
mapMap
hashmapHashMap
listList
arraylistArrayList
collectionCollection
iteratorIterator
  • 作者:龙源lll
  • 原文链接:https://blog.csdn.net/Lzy410992/article/details/115614760
    更新时间:2022-07-14 10:38:13