BackEnd
[Spring] 내가 보기 위해 만드는 편리한 annotation 모음
mingg123
2021. 11. 18. 12:29
1. JsonInclude
RequestBody로 null인 값은 보고 싶지 않을 경우
@JsonInclude(JsonInclude.Include.NON_NULL) // null 인 값은 안보겠다. response body로
보시다 싶이 null인 값은 body로 오지 않음을 알 수 있다.
2. AssertTrue
AssertTure를 사용할 경우 메소드 이름은 앞이 is로 시작해야 정상 동작함을 주의하자.
@AssertTrue(message = "yyyyMM 형식에 맞지 않습니다.")
public boolean isReqYearMonthValidation() {
// Sytstem.out.println("AsertTrue");
try {
LocalDate localDate = LocalDate.parse(this.getReqYearMonth() + "01",
DateTimeFormatter.ofPattern("yyyyMMdd"));
} catch (Exception e) {
return false;
}
return true;
}
@SpringBootApplication | Spring boot application 설정 |
@Controller | View를 제공하는 controller로 설정 |
@RestController | REST API를 제공하는 controller로 설정 |
@RequestMapping | URL주소를 맵핑 |
@GetMapping | Http GetMethod URL 주소 맵핑 |
@PostMapping | Http PostMethod URL 주소 맵핑 |
@PutMapping | Http PutMethod URL 주소 맵핑 |
@DeleteMapping | Http DeleteMethod URL 주소 맵핑 |
@RequestParam | URL Query Parameter 맵핑 |
@RequestBody | Http Body를 Parsing 맵핑 |
@Valid | POJO Java class의 검증 |
@Configuration | 1개 이상의 bean을 등록할 때 설정 |
@Component | 1개의 Class 단위로 등록 할 때 사용 |
@Bean | 1개의 외부 library로 부터 생성한 객체를 등록 시 사용 |
@Autowired | DI를 위한 곳에 사용 |
@Qualifier | @Autowired 사용시 bean이 2개 이상 일때 명시적 사용 |
@Resource | @Autowired + @ Qualifier의 개념으로 이해 |
@Aspect | AOP 적용시 사용 |
@Before | AOP 메소드 이전 호출 지정 |
@After | AOP 메소드 호출 이후 지정 예외 발생 포함 |
@Around | AOP이전/이후 모두 포함 예외 발생 포함 |
@AfterReturning | AOP메소드의 호출이 정상일 때 실행 |