请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

更新用户信息的时候为什么需要新建updateUser 而不直接采用传过来的更新信息user

更新用户信息的时候为什么需要新建updateUser 而不直接采用传过来的更新信息user

正在回答

插入代码

1回答

同学你好

hi同学,我们调用的 是updateByPrimaryKeySelective这个方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<update id="updateByPrimaryKeySelective" parameterType="com.mmall.pojo.User" >
 update mmall_user
 <set >
   <if test="username != null" >
     username = #{username,jdbcType=VARCHAR},
   </if>
   <if test="password != null" >
     password = #{password,jdbcType=VARCHAR},
   </if>
   <if test="email != null" >
     email = #{email,jdbcType=VARCHAR},
   </if>
   <if test="phone != null" >
     phone = #{phone,jdbcType=VARCHAR},
   </if>
   <if test="question != null" >
     question = #{question,jdbcType=VARCHAR},
   </if>
   <if test="answer != null" >
     answer = #{answer,jdbcType=VARCHAR},
   </if>
   <if test="role != null" >
     role = #{role,jdbcType=INTEGER},
   </if>
   <if test="createTime != null" >
     create_time = #{createTime,jdbcType=TIMESTAMP},
   </if>
   <if test="updateTime != null" >
     update_time = now(),
   </if>
 </set>
 where id #{id,jdbcType=INTEGER}
</update>


注意看他的实现,自己new之后只更新想更新的。不必要的重复更新就不更新了。


0 回复 有任何疑惑可以回复我~
  • 提问者 94年的矿泉水 #1
    在updateUserInfomation中,要把更新的updateUser放入data中返回给Controller:
      return ServerResponse.createBySuccess("更新个人信息成功",updateUser);
    在controller中要把返回的值放入session中。这样session中存放的值就不全。。。后面取session值的时候,里面没有自己想要的字段怎么办?
     session.setAttribute(Const.CURRENT_USER,response.getData());
    回复 有任何疑惑可以回复我~ 2018-02-28 10:19:46
  • Geely 回复 提问者 94年的矿泉水 #2
    目前session里通过update之后的确有这个问题,赞同学。可以修改一下,session里一期主要是判断是否登录所用。里面的字段也不都全部使用。
    回复 有任何疑惑可以回复我~ 2018-03-02 15:56:08
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号