MyBatis中别名的设置


在sqlMapperConfig中进行设置;

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE configuration
    PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>
<!--非自定义别名,所有javaJDK中的类都定义了别名,别名是类名不区分大小写: map 替换java.util.Map
如果是包装类,还可以使用基本数据类型:int 替换java.lang.Integer
    --> 
    <typeAliases>
      <!--自定义别名-->
      <typeAlias  alias="Person" type="com.stone.model.Person"/> 
    </typeAliases> 

    <environments default="development">
     ...
    </environments>
    <mappers>
        ...
    </mappers>
</configuration>

在personMapper.xml中可以定义sql片段

<sql id="cols">
    id,name,addr,birthday
</sql>

<select id="sel">
   select <include refid="cols" /> from person
</select>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM