在mybatis-config.xml文件中配置
第一种:单独一个一个的配置类的别名
<!-- 配置类的别名,在userMapper.xml的parameterType或resultType来使用 -->
<typeAliases>
<!-- 单独一个一个的配置类的别名 -->
<typeAlias type="com.mybatis.pojo.User" alias="User"/>
</typeAliases>
<!-- 根据id查询信息,别名方式 -->
<!--<select id="load" parameterType="java.lang.Integer" resultType="com.mybatis.pojo.User">就可以改成下面这种-->
<select id="load" parameterType="java.lang.Integer" resultType="User">
select * from t_user where id = #{id}
</select>
第二种:全部自动配置类的别名【推荐使用】
name是实体的全路径
<!-- 配置类的别名,在userMapper.xml的parameterType或resultType来使用 -->
<typeAliases>
<!-- 全部自动配置类的别名 -->
<package name="com.mybatis.pojo"/>
</typeAliases>
<!-- 登录查询 -->
<!--<select id="login" parameterType="com.mybatis.pojo.User" resultType="com.mybatis.pojo.User">就可以变成下面这种-->
<select id="login" parameterType="User" resultType="User">
select * from t_user
<where>
<if test="username != null and username != ''">
username = #{username}
</if>
<if test="password != null and password != ''">
password = #{password}
</if>
</where>
</select>
<!-- 添加信息 -->
<insert id="add" parameterType="UserInfo">
insert into t_userinfo(uid,name,sex,birthday)
values(#{uid},#{name},#{sex},#{birthday})
</insert>