配置properties:
方式一:
方式二:![](https://img-blog.csdnimg.cn/2019080410563
948.PNG
方式三:
2:为环境中的resultType和parameterType提供别名
<typeAliases>
<!--typeAlias用于配置别名。type属性指定的是实体类全限定类名。alias属性指定别名,当指定了别名就不再区分大小写
<typeAlias type="com.itheima.domain.User" alias="user"></typeAlias>-->
<!-- 用于指定要配置别名的包,当指定之后,该包下的实体类都会注册别名,并且类名就是别名,不再区分大小写-->
<package name="com.itheima.entity"></package>
</typeAliases>
**3.解决数据库字段跟实体类属性不一致问题:**
**1.在mapper映射的xml文件中的sql加上别名**
<select id="findPojoAll" resultMap="pojoMap">
SELECT `username` userName,birthday UserBirthDay,sex userSex,address UserAddress FROM `user` WHERE id=41
</select>
优点:直接作用于数据库,效率高,但是多个sql需起多次别名,复杂
**2.使用resultMap配置 <!-- 配置 查询结果的列名和实体类的属性名的对应关系 -->**
id自定义,type是参数的实体类全名
<mapper namespace="com.itheima.dao.IUserDao">
<resultMap id="pojoMap" type="userpojo">
<id property="userId" column="id"/>
<result property="userName" column="username"/>
<result property="UserBirthday" column="birthday"/>
<result property="UserSex" column="sex"/>
<result property="UserAddress" column="address"/>
</resultMap>
<select id="findPojoAll" resultMap="pojoMap">
select * from `user`
</select>
<mappers>
mapper的resource适用于xml方式
<mapper resource="com/itheima/dao/IUserDao.xml"></mapper>
mapper的resource适用于注解方式
<mapper class="com.itheima.dao.UserDao"/>
**package标签是用于指定dao接口所在的包,当指定了之后就不需要在写mapper以及resource或者class了**
<package name="com.itheima.dao"></package>
</mappers>