생산성
유지보수성
재사용성
신뢰성
표준화
확장성
하지만, 학습난이도 증가, 자유도 감소, 패키지 용량 증가, 프레임워크 의존 위험 증가 될 수 있다.
AOP(Aspect Oriented Programming)
Filter --> Interceptor --> Aspect1, Aspect2, ...
필요한 부분에 AOP(Aspect)만 추가해서 사용하면 된다.
*filter : 암복호화, 인코딩 변환, XSS 방어
*Interceptopr : HTTP 프로토콜 레벨 로그인 체크, 권한 체크
*Aspect : 비즈니스 로직 관련, 그룹 로깅, 트랜잭션 등 비즈니스 단의 method 보다 세밀한 조정이 필요한 경우 사용
@GetMappgin(path=uri 주소)
path에 uri 주소를 입력하면 해당 주소로 API가 매핑된다.
@RestController
public class StudyController {
@GetMapping(path = "/sample") //path is uri, post 로 request를 보낸다.
public String sample() {
String ret ="Hello world!"; //화면에 text로 보여짐
return ret;
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>html file</title>
</head>
<body>
HELLO WORLD
</body>
</html>
@Controller
public class StudyController {
@GetMapping(path = "/sample") //path is uri
public String sample() {
String ret ="Hello world!";
ret = "helloworld"; //resources template에 생성한 html파일 이름과 같게 생성해야된다.
return ret;
}
}
@GetMapping(path = "/sample")
public String selectSample() {
String ret ="";
ret = "helloworld";
return ret;
}
@PostMapping(path = "/sample")
public String insertSample() {
String ret ="";
ret = "helloworld";
return ret;
}
@PutMapping(path = "/sample")
public String updateSample() {
String ret ="";
ret = "helloworld";
return ret;
}
@DeleteMapping(path = "/sample")
public String deleteSample() {
String ret ="";
ret = "helloworld"; //화면에 text로 보여짐
return ret;
}
@SpringBootApplication에서 필요한 자원을 스캔한뒤에 bean으로 생성한다.
DI injection :: @Authwired를 통해 bean을 할당함.
Component :: service | controller | repositry
생성자가 호출된 후에 @PostConstruct가 바로 호출된다.
종료되기 직전에는 @PreDestroy
따라서 @PostContructor로 선언된 메소드에서 @Authwired된 객체를 print해보면 객체가 메모리에 할당된 것을 확인할 수 있다.
StudyService studyServicce;
@Autowired
public StudyController(StudyService service) {
this.studyServicce = service;
}
생성자의 전달인수로 할당 받게 하는게 권장된다.