In a specific mapper.xml file, defining a lot of statement,statement requires parametertype specifying the type of input parameter, the type of mapping that needs to be resulttype to specify the output result.
If you enter a type full path when specifying a type, it is inconvenient to develop, you can define some aliases for the type specified by ParameterType or Resulttype, and the alias definition in mapper.xml to facilitate development.
one. MyBatis Default support aliases
Alias |
Types of mappings |
_byte |
Byte |
_long |
Long |
_short |
Short |
_int |
Int |
_integer |
Int |
_double |
Double |
_float |
Float |
_boolean |
Boolean |
String |
String |
Byte |
Byte |
Long |
Long |
Short |
Short |
Int |
Integer |
Integer |
Integer |
Double |
Double |
Float |
Float |
Boolean |
Boolean |
Date |
Date |
Decimal |
BigDecimal |
BigDecimal |
BigDecimal |
As shown in the following illustration: Int is an alias;
two. Custom aliases
Individual definition aliases
Use the typealiases tag to define the alias; alias the Cn.itcast.mybatis.po.User to User;
[HTML] view plain copy <!--alias definition-<typeAliases> <!--define type for a single alias: path alias for a type : Alias--<typealias type= "Cn.itcast.mybatis.po.User" alias= "User"/> </typeAliases>
Bulk definition aliases
MyBatis automatically scans the PO class in the package, automatically defines the alias, which is the class name (uppercase or lowercase, usually lowercase)
For example: Cn.itcast.mybatis.po.User alias for user or user;
[HTML] view plain copy <!--alias definition-<typeAliases> <!--batch alias definition, specify package name, MyBatis automatically scans the PO class in the package, automatically Define aliases, which are class names (either uppercase or lowercase, usually lowercase)-<package name= "Cn.itcast.mybatis.po"/> </typeAliases>
In the Mapper.xml file
Before the alias is defined
[HTML] view plain copy <select id= "Finduserbyid" parametertype= "int" resulttype= "Cn.itcast.mybatis.po. User "> select * from USER where id = #{id} </select>
Alias user is used in direct resulttype after defining aliases;
[HTML] View plain copy <select id= "Finduserbyid" parametertype= "int" resulttype= "User" >