请求体封装
model.domin.request
封装对象专门记录请求参数,要实现序列化接口,继承Serializabll
controller层注册与登录接口实现
@RestController
//@RestController 注解适用于编写 restful 风格的 api,返回值默认为 json 类型
@RequestMapping("/user")
public class UserController {
@Resource
private UserService userService;
@PostMapping("/register")
public Long userRegister(@RequestBody UserRegisterRequest userRegisterRequest) {
if (userRegisterRequest == null){
return null;
}
String userAccount = userRegisterRequest.getUserAccount();
String userPassword = userRegisterRequest.getUserPassword();
String checkPassword = userRegisterRequest.getCheckPassword();
if(StringUtils.isAnyBlank(userAccount,userPassword,checkPassword)){
return null;
}
return userService.userRegister(userAccount,userPassword,checkPassword);
}
@PostMapping("/login")
public User userLogin(@RequestBody UserLoginRequest userLoginRequest, HttpServletRequest request){
if (userLoginRequest == null){
return null;
}
String userAccount = userLoginRequest.getUserAccount();
String userPassword = userLoginRequest.getUserPassword();
if(StringUtils.isAnyBlank(userAccount,userPassword)){
return null;
}
User user = userService.userLogin(userAccount, userPassword,request);
return user;
}
}