MyBatis别名

转http://blog.csdn.net/qq_28885149/article/details/51694733

MyBatis中如果每次配置类名都要写全称也太不友好了,我们可以通过在主配置文件中配置别名,就不再需要指定完整的包名了。

别名的基本用法:

<configuration>  
    <typeAliases>  
      <typeAlias type="com.domain.Student" alias="Student"/>  
  </typeAliases>  
  ......  
</configuration>  

但是如果每一个实体类都这样配置还是有点麻烦这时我们可以直接指定package的名字, mybatis会自动扫描指定包下面的javabean,并且默认设置一个别名,默认的名字为: javabean 的首字母小写的非限定类名来作为它的别名(其实别名是不去分大小写的)。也可在javabean 加上注解@Alias 来自定义别名, 例如: @Alias(student)

<typeAliases>  
    <package name="com.domain"/>  
</typeAliases>  
 

这样,在Mapper中我们就不用每次配置都写类的全名了,但是有一个例外,那就是namespace。

namespace属性

在MyBatis中,Mapper中的namespace用于绑定Dao接口的,即面向接口编程。

它的好处在于当使用了namespace之后就可以不用写接口实现类,业务逻辑会直接通过这个绑定寻找到相对应的SQL语句进行对应的数据处理

student = (Student) session.selectOne("com.domain.Student.selectById", new Integer(10));
<mapper namespace="com.domain.Student">    
  
    <select id="selectById" parameterType="int" resultType="student">    
       select * from student where id=#{id}    
    </select>  
       
</mapper>  
原文地址:https://www.cnblogs.com/miye/p/7215889.html