SpringBoot项目盲点记录一:XML文件配置
一、在写SQL语句时一定要注意update的返回值只有bool值和void
错误示例:
<update id="updateUser" reultType="com.kkkoke.networkrepair.pojo.User">
update `user`
set `username` = #{username}, `password` = #{password}, `name` = #{name}
where id = #{id}
</update>
<update id="updateUser" reultType="list">
update `user`
set `username` = #{username}, `password` = #{password}, `name` = #{name}
where id = #{id}
</update>
Dao层代码:
// 修改用户信息
User updateUser(User user);
正确示例:
<update id="updateUser">
update `user`
set `username` = #{username}, `password` = #{password}, `name` = #{name}
where id = #{id}
</update>
Dao层代码:
// 修改用户信息
Integer updateUser(User user);
二、当SQL语句查询返回对象时,应当配置reslutMap,否则会报错
正确示例:
<select id="selectAllUser" resultMap="userMap">
select * from `user`
</select>
<resultMap id="userMap" type="com.kkkoke.networkrepair.pojo.User">
<id property="id" column="id"/>
<result property="username" column="username"/>
<result property="password" column="password"/>
<result property="name" column="name"/>
</resultMap>