Я пытаюсь проверить валидацию в моем сервисе для полей, но когда я добавляю сообщение для ответа, не отображать (сообщение и статус) в почтовом человеке
Я много раз искал в Stackoverflow, нет ответа для моегоcase
Entity:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, unique = true)
@NotNull
private String clientName;
@Column(name = "date_of_birth", nullable = false)
@Temporal(TemporalType.DATE)
/** @JsonFormat(pattern="dd/MM/yyyy") **/
private Date dateOfBirth;
@Column(nullable = false)
@NotNull
private String mobileNumber;
@Column(nullable = false)
@NotNull
@Email(message = "Email should be valid")
private String email;
@Column(nullable = false)
@NotNull
private String address;
@Column(nullable = false)
@NotNull
private String sex;
@NotNull(message = "weight cannot be null")
private Integer weight;
@NotNull(message = "hight cannot be null")
private Integer hight;
@Column(nullable = false)
@NotNull
private String healthNote;
@Column(nullable = false)
@NotNull
private String importantNote;
@Column(nullable = false)
@NotNull
private String personToContact;
@Column(nullable = false)
@NotNull
private String relation;
@Column(nullable = false)
@NotNull
private String phoneNumber;
Контроллер:
@PostMapping("/uploadProfileClient")
public ResponseEntity<?> uploadMultipartFile(@Valid @RequestPart("addClient") String clientNew ,@Valid @RequestPart(value = "image") MultipartFile image,BindingResult result) throws JsonParseException, JsonMappingException, IOException {
clientEntity client = null;
Map<String,Object> response = new HashMap<>();
if(result.hasErrors()) {
List<String> errors = result.getFieldErrors().stream().map(err -> "The field '" + err.getField() +"' "+ err.getDefaultMessage()) .collect(Collectors.toList());
response.put("Errors",errors);
return new ResponseEntity<Map<String,Object>>(response, HttpStatus.BAD_REQUEST);
}
ObjectMapper mapper = new ObjectMapper();
client = mapper.readValue(clientNew, clientEntity.class);
client.setImage(image.getBytes());
try {
clientService.save(client);
} catch ( DataAccessException e) {
response.put("message", "Error when inserting into the database");
response.put("error", e.getMessage().concat(": ").concat(e.getMostSpecificCause().getMessage()));
return new ResponseEntity<Map<String,Object>>(response,HttpStatus.INTERNAL_SERVER_ERROR);
}
response.put("message", "the client data has been created successfully!");
response.put("client", client);
return new ResponseEntity<Map<String,Object>>(response,HttpStatus.CREATED);
}
Я отправлю данные в формате json и файл, ответ не отображается в почтальоне, пожалуйста, мне нужен ответ.