mybatis-全局配置文件-mybatis-config.xml- typeAliases-5

xiaoxiao2021-02-28  120

为类起别名,如果觉得 EmployeeMapper.xml,resultType写全类名过长的话: 但是推荐写全类名

<mapper namespace="com.stayreal.mybatis.EmployeeMapper"> <select id="getEmpById" resultType="com.stayreal.mybatis.Employee"> select * from tbl_employee where id = #{id} </select> <mapper>

三种方式

mybatis-config.xml

<typeAliases> <!-- 为某个java类型起别名 type:要起别名类型的全类名;默认别名就是类名小写,employee alias:指定新的别名 别名不区分大小写 --> <!--<typeAlias type="com.stayreal.mybatis.Employee" />--> <!--<typeAlias type="com.stayreal.mybatis.Employee" alias="emp"/>--> <!-- 批量起别名:为某个包下的所有类批量起别名 name:指定包名(为当前包及所有下面的后代包每个类起一个默认别名(默认类名小写)) --> <package name="com.stayreal.mybatis"/> <!-- 可以使用@Alias("emp")注解起别名 在类上面添加 注意是在有包扫描的情况下--> <!-- 包扫描 <package name="com.stayreal.mybatis"/>--> </typeAliases>
转载请注明原文地址: https://www.6miu.com/read-35534.html

最新回复(0)