我已经被这个问题困扰了2天,基本上,我的userrequest类中有4个属性,我正在运行我的post请求到usercontroller类中的createuser函数,在我尝试向userrequest类添加一个新属性“age”之前,一切都运行得很好,但问题是,请求到达时仍然只有我最初拥有的四个属性,然后当我试图从userrequest中删除四个属性中的一个时,我仍然在createuser函数中接收它
用户请求.java
public class UserRequest {
@NotNull
@Size(min = 3)
private String firstName;
@NotNull
@Size(min = 3)
private String lastName;
@NotNull
@Email
private String email;
@NotNull
@Size(min = 8)
private String password;
@NotNull
private String age;
//....getters and setters
用户控制器.java
@RestController
@RequestMapping("/users")
public class UserController {
@PostMapping
public ResponseEntity<Object> createUser(@RequestBody @Valid UserRequest userRequest) throws Exception {
System.out.println(userRequest);
if(userRequest.getFirstName().isEmpty() ) throw new UserException(ErrorMessages.MISSING_REQUIRED_FIELD.getErrorMessage());
//UserDto userDto = new UserDto();
ModelMapper modelMapper = new ModelMapper();
UserDto userDto = modelMapper.map(userRequest, UserDto.class);
//BeanUtils.copyProperties(userRequest, userDto); //couche presentation
UserDto createUser = userService.createUser(userDto); //Appel au service
//UserResponse userResponse = new UserResponse();
UserResponse userResponse = modelMapper.map(createUser, UserResponse.class);
//BeanUtils.copyProperties(createUser, userResponse); //Copier vers la reponse
return new ResponseEntity<>(userResponse,HttpStatus.CREATED) ;
}
失眠症后处理请求
{
"firstName" : "outiti",
"lastName" : "ayoub",
"email" : "outiti@gmail.com",
"password" : "12345678",
"age" : "15"
}
请求正文接收
暂无答案!
目前还没有任何答案,快来回答吧!