实现用户信息修改

This commit is contained in:
F嘉阳
2018-02-22 20:14:16 +08:00
parent b6def717f4
commit 355c1c171f
5 changed files with 73 additions and 49 deletions

View File

@@ -0,0 +1,46 @@
package com.fjy.spring.controller;
import com.fjy.spring.domain.TbUser;
import com.fjy.spring.enums.ResultEnum;
import com.fjy.spring.exception.UserException;
import com.fjy.spring.properties.ServerProperties;
import com.fjy.spring.service.UserService;
import com.fjy.spring.untils.CodingUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigInteger;
@Controller
public class UpdateController {
@Autowired
private UserService userService;
@Autowired
private ServerProperties serverProperties;
@Resource
HttpServletRequest request;
@PostMapping(value = "/home/userUpdate")
public String doUserUpdate(TbUser tbUser)throws Exception{
if (tbUser.getColuserid()==null){
throw new UserException(ResultEnum.ID_NULLPOINT);
}
if (tbUser.getColpassword()!=null&&tbUser.getColpassword()!=""){
//加密用户密码
tbUser.setColpassword(new BigInteger(CodingUtil.encryptSHA(tbUser.getColpassword().getBytes())).toString(32));
}
if (userService.doRegisterService(tbUser)){
System.out.println(tbUser.getColname()+" 信息更新成功");
return "redirect:" + request.getScheme() + "://" + request.getServerName() + ":"
+ serverProperties.getPortNum() + request.getContextPath() + "/home/user";
// return "login";
}
throw new UserException(ResultEnum.UNKOWN_ERROR);
}
}

View File

@@ -1,4 +1,5 @@
package com.fjy.spring.domain;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@@ -11,7 +12,9 @@ public class TbUser {
private Integer coluserid;
@NotNull(message = "用户名必填")
private String colname;
@NotNull(message = "密码不能为空")
@Column(updatable=false)
/*@NotNull(message = "密码不能为空")*/
private String colpassword;
private String colemail;
@NotNull(message = "学号必填")

View File

@@ -10,7 +10,8 @@ public enum ResultEnum {
WRONGPASS(105,"用户名或密码错误"),
ILLEGAL_ACCESS(106,"非法访问"),
WRONG_FORM(107,"表单错误"),
EMPTY_DATA(108,"无数据")
EMPTY_DATA(108,"无数据"),
ID_NULLPOINT(109,"id为空"),
;
private Integer code;
private String msg;