心得用户个人信息的查询和更改

This commit is contained in:
muamua 2018-10-13 16:46:59 +08:00
parent 3049b3c0b4
commit a1d88bbe9c
5 changed files with 67 additions and 11 deletions

View File

@ -17,11 +17,12 @@ public class UserController {
@Autowired @Autowired
private UserService userService; private UserService userService;
@RequestMapping(value = "/getUser") @RequestMapping(method = RequestMethod.POST,value = "/updateProfile")
public User getUser(int id){ public int updateProfile(String userName, String password, String name,
return userService.selectById(id); String phone, String email, String address, String idNumber){
User user = new User(userName,password,name,phone,email,address,idNumber);
return userService.updateProfile(user);
} }
/** /**
* 注册 * 注册
* @param userName * @param userName
@ -39,7 +40,6 @@ public class UserController {
User user = new User(userName,password,name,phone,email,address,idNumber); User user = new User(userName,password,name,phone,email,address,idNumber);
return userService.register(user); return userService.register(user);
} }
/** /**
* 登录 * 登录
* @param userName * @param userName
@ -53,5 +53,14 @@ public class UserController {
} }
return 1; return 1;
} }
/**
* 查看用户资料
* @param userName
* @return
*/
@RequestMapping(method = RequestMethod.POST, value = "/getProfile")
public User getProfile(String userName){
return userService.selectByUserName(userName);
}
} }

View File

@ -6,16 +6,12 @@ import org.springframework.stereotype.Component;
@Component @Component
public interface UserMapper { public interface UserMapper {
int deleteByPrimaryKey(Integer userId); int deleteByPrimaryKey(Integer userId);
int insert(User record); int insert(User record);
int insertSelective(User record); int insertSelective(User record);
User selectByPrimaryKey(Integer userId); User selectByPrimaryKey(Integer userId);
int updateByPrimaryKeySelective(User record); int updateByPrimaryKeySelective(User record);
int updateByPrimaryKey(User record); int updateByPrimaryKey(User record);
User selectByUserNameAndPassword(User user); User selectByUserNameAndPassword(User user);
User selectByUserName(String userName);
int updateByUserNameSelective(User record);
} }

View File

@ -10,4 +10,8 @@ public interface UserService {
int register(User user); int register(User user);
User login(String userName, String password); User login(String userName, String password);
User selectByUserName(String userName);
int updateProfile(User user);
} }

View File

@ -30,5 +30,13 @@ public class UserServiceImpl implements UserService {
return userMapper.selectByUserNameAndPassword(user); return userMapper.selectByUserNameAndPassword(user);
} }
@Override
public User selectByUserName(String userName) {
return userMapper.selectByUserName(userName);
}
@Override
public int updateProfile(User user) {
return userMapper.updateByUserNameSelective(user);
}
} }

View File

@ -156,4 +156,43 @@
from user from user
where user_name = #{userName,jdbcType=VARCHAR} and password = #{password,jdbcType=VARCHAR} where user_name = #{userName,jdbcType=VARCHAR} and password = #{password,jdbcType=VARCHAR}
</select> </select>
<select id="selectByUserName" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from user
where user_name = #{userName,jdbcType=VARCHAR}
</select>
<update id="updateByUserNameSelective" parameterType="cn.mafangui.hotel.entity.User">
update user
<set>
<if test="userName != null">
user_name = #{userName,jdbcType=VARCHAR},
</if>
<if test="password != null">
password = #{password,jdbcType=VARCHAR},
</if>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
</if>
<if test="phone != null">
phone = #{phone,jdbcType=VARCHAR},
</if>
<if test="email != null">
email = #{email,jdbcType=VARCHAR},
</if>
<if test="address != null">
address = #{address,jdbcType=VARCHAR},
</if>
<if test="idNumber != null">
id_number = #{idNumber,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set>
where user_name = #{userName,jdbcType=INTEGER}
</update>
</mapper> </mapper>