出现问题时mapper.xml里的内容。重点关注:注意这里!!!上下两部分对应看
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nowcoder.community.dao.UserMapper">
<!-- 注意这里!!!!!! 注意这里!!!!! 注意这里!!!!!-->
<insert id="insertFields">
username, password, salt, email, type, status, activation_code, header_url, create_time
</insert>
<!-- 提炼字段内容-->
<sql id="selectFields">
id, username, password, salt, email, type, status, activation_code, header_url, create_time
</sql>
<select id="selectById" resultType="User">
select <include refid="selectFields"></include>
from user
where id = #{id}
</select>
<insert id="insertUser" parameterType="User" keyProperty="id">
<!-- 注意这里!!!!!! 注意这里!!!!! 注意这里!!!!!-->
insert into user (<include refid="insertFields"></include>)
values(#{username}, #{password}, #{salt}, #{email}, #{type}, #{status}, #{activationCode}, #{headerUrl}, #{createTime})
</insert>
</mapper>
解决方式:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nowcoder.community.dao.UserMapper">
<!-- 注意这里把该字段注释掉就可以了!!!注意这里把该字段注释掉就可以了!!!注意这里把该字段注释掉就可以了!!! -->
<!-- <insert id="insertFields">-->
<!-- username, password, salt, email, type, status, activation_code, header_url, create_time-->
<!-- </insert>-->
<!-- 提炼字段内容-->
<sql id="selectFields">
id, username, password, salt, email, type, status, activation_code, header_url, create_time
</sql>
<!-- id="selectById":表示这部分SQL是为UserMapper中的selectById方法服务的 -->
<select id="selectById" resultType="User">
select <include refid="selectFields"></include>
from user
where id = #{id}
</select>
<insert id="insertUser" parameterType="User" keyProperty="id">
<!-- 注意这里把该字段写全就可以了!!!注意这里把该字段写全就可以了!!!注意这里把该字段写全就可以了!!! -->
insert into user (username, password, salt, email, type, status, activation_code, header_url, create_time)
values(#{username}, #{password}, #{salt}, #{email}, #{type}, #{status}, #{activationCode}, #{headerUrl}, #{createTime})
</insert>
</mapper>
倒置分析:
可以看到select语句的提取没有问题,而insert语句对字段的提取出现问题。其他的看不透,暂时就默认为bug好了。。