π©π»βπ¦° μ ν¨μ± κ²μ¬ / μμΈ μ²λ¦¬
μ λͺ©
κ³Ό λ΄μ©
μ νμ ν¬ν¨ βμ λͺ©
κ³Ό λ΄μ©
μ 곡백μΌλ‘λ§ μ΄λ£¨μ΄μ§ μλ μλ€. βμ λͺ©
μ 1κΈμ μ΄μ 30κΈμ μ΄ν βλ΄μ©
μ 1κΈμ μ΄μ 1000κΈμ μ΄ν βκ²μ ν€μλ
λ 곡백μ μ μΈν 1κΈμ μ΄μμ΄μ΄μΌ νλ€. βjavax
β jakarta
PostRequestDTO
@NotBlank(message = "μ λͺ©μ μ
λ ₯ν΄μ£ΌμΈμ")
@Size(min = 1, max = 30, message = "μ λͺ©μ 1κΈμ μ΄μ 30κΈμ μ΄νμ¬μΌ ν©λλ€")
private String title;
SearchDTO
@Size(min = 1, message = "κ²μ ν€μλλ 곡백μ μ μΈν 1κΈμ μ΄μμ΄μ΄μΌ ν©λλ€.")
private String keyword;
public SearchDTO(String keyword) {
this.keyword = keyword.trim();
}
@ControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(NoSuchElementException.class)
public ResponseEntity<String> handleNoSuchElementException(NoSuchElementException e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("κ²μκΈμ μ°Ύμ μ μμ΅λλ€.");
}
}
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<String> handleValidationExceptions(MethodArgumentNotValidException ex) {
return ResponseEntity.badRequest().body("μ ν¨μ± κ²μ¬ μ€ν¨: "
+ ex.getBindingResult()
.getFieldError()
.getDefaultMessage());
}