본문 바로가기

validator3

Spring Web MVC - @ResponseBody, ResponseEntity Spring Web MVC - 핸들러 메소드 4 @RequestBody @RequestBody 는 핸들러의 아규먼트로 받아 올 수 있다. 요청 본문(body)에 들어있는 데이터를 HttpMessageConverter를 통해 변환한 객체로 받아올 수 있다. HttpMessageConverter : 스프링 MVC 설정 (WebMvcConfigurer) 에서 설정할 수 있다. 이 때 configureMessageConverters 를 오버라이딩하면 기본 메시지 컨버터를 대체하게 되어, 기본설정이 바뀔 수 있으므로 조심한다. 대신 extendMessageConverters 를 이용하면 원하는 메시지 컨버터를 추가할 수 있다. (객체를 XML으로 바꾼다든지) 기본 컨버터는 WebMvcConfigurationSup.. 2021. 2. 21.
Spring - Validation Validation 추상화 org.springframework.validation.Validator 주로 spring MVC 에서 사용하지만, 웹 MVC 전용은 아니다. 애플리케이션에서 사용하는 객체 검증을 위한 일반적 인터페이스이다. 예제를 만들기 위해 이벤트를 하나 생성한다. @Getter @Setter public class RedEvent { Integer id; String title; } (lombok 을 사용하여 자동 게터, 세터를 생성한다고 하자) 이제 위 이벤트를 가지고 Validator 를 구현해보자. Validator를 사용하려면 두 가지 메소드를 구현해야 한다. supports, validate public class RedEventValidator implements Validat.. 2021. 1. 12.
[Spring Boot] 10 - @ConfigurationProperties 사용법 Spring Boot 010 - @ConfigurationProperties 의 여러 장점, 일부 단점 2.8.5 Third-party Configuration 클래스를 주석(annotate)하기 위해 @ConfigurationProperties 를 사용하는 것 뿐 아니라, @Bean 메소드에서도 사용할 수 있습니다. 건드릴 수 없는 클래스가 있을 때, ​ 즉, @ConfigurationProperties("whiteship") @Component public class WhiteshipProperties { } 라고 클래스 위에 어노테이션을 명시할 수 없을 때, 메인 클래스에 와서 public class Application { @Bean @ConfigurationProperties("whiteship.. 2020. 3. 29.
728x90