<resultMap id="userMap" type="com.cast.pojo.User"> <id column="id" property="userId"/> <result column="username" property="userName"/> <result column="sex" property="userSex"/> <result column="birthday" property="userBirthday"/> <result column="address" property="userAddress"/> resultMap>
mybatis的resultMap property爆红
虽然我写了全路径类名,但是就是不能找到实体类的属性,最后的原因,就是在SQL的配置文件sqlMapperConfig.xml中添加别名,而且要写在环境的上边,写下下边configuration爆红
<typeAliases> <typeAlias type="com.cast.pojo.User" alias="user"/> typeAliases> DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"><configuration> <typeAliases> <typeAlias type="com.cast.pojo.User" alias="user"/> typeAliases> <environments default="mysql"> <environment id="mysql"> <transactionManager type="JDBC">transactionManager> <dataSource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/mybatis"/> <property name="username" value="root"/> <property name="password" value="654321"/> dataSource> environment> environments> <mappers> <mapper resource="com/cast/dao/UserDao.xml">mapper> mappers>configuration>
最后不要忘了,修改映射文件Daomapper.xml中的路径
直接写别名,全路径已经换为别名了
<resultMap id="userMap" type="user"> <id column="id" property="userId"/> <result column="username" property="userName"/> <result column="sex" property="userSex"/> <result column="birthday" property="userBirthday"/> <result column="address" property="userAddress"/> resultMap>
来源地址:https://blog.csdn.net/gar6899__/article/details/129968716