一、mybatis-config.xml代码如下:
<?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>
<properties resource="jdbc.properties"/>
<typeAliases>
<package name="com.atguigu.mybatis.pojo"/>
</typeAliases>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</dataSource>
</environment>
</environments>
<mappers>
<package name="com.atguigu.mybatis.mapper"></package>
</mappers>
</configuration>
<typeAliases>
<package name="com.atguigu.mybatis.pojo"/>
</typeAliases>
二、typeAlias:设置某个具体的类型的别名属性:
- type:需要设置别名的类型的全类名
- alias:设置此类型的别名,且别名不区分大小写。若不设置此属性,该类型拥有默认的别名,即类名
<!--<typeAlias type="com.atguigu.mybatis.pojo.User"></typeAlias>-->
<!--<typeAlias type="com.atguigu.mybatis.pojo.User" alias="user"></typeAlias>-->
<!--<typeAlias type="com.atguigu.mybatis.pojo.User"></typeAlias> -->
<!--以包为单位,设置改包下所有的类型都拥有默认的别名,即类名且不区分大小写-->
三、映射文件中的sql查询语句:
修改前: <select id="getAllUser" resultType="com.atguigu.mybatis.pojo.User">
<!--List<User> getAllUser();-->
<select id="getAllUser" resultType="com.atguigu.mybatis.pojo.User">
select * from t_user
</select>
修改后: <select id="getAllUser" resultType="user">
<!--List<User> getAllUser();-->
<select id="getAllUser" resultType="user">
select * from t_user
</select>