MyBatis中typealiases的使用

以前一直体会不到typealiases的作用,今天遇到了问题!

问题描述

Mybatis有个代码生成工具,生成的代码里面有mapper.xml文件,mapper.xml中的sql语句会用parameterType这个属性,而这个值可能是我们自定义的对象,此时,如果没有typealiases,我们就需要为parameterType指定全路径:

[html] view plain copy
  1. <span style="font-size:14px;"><select id="getStudent" parameterType="com.csct.domain.StudentEntity" resultType="com.csct.domain.StudentEntity" resultMap="studentResultMap">span>  

代码自动生成工具生成的mapper.xml文件中不带全路径,那么,如果有三、四十个实体对象,我们岂不是要修改的地方太多了。

解决办法

这个时候,我们是不是很期望有一个方式,能把com.csct.domain下的实体全部给加载进来,mapper.xml遇到不识别的类就在这里查找呢?你都想到了,Mybatis当然也能想到吧,typealiases就是为此而生的。使用特简单,如下:

[html] view plain copy
  1. <span style="font-size:14px;"><configuration>  
  2.     <typeAliases>  
  3.       

你可能感兴趣的:(Java基础)