Spring 개념정리

kwlee·2021년 9월 14일
0

Spring 구성

https://docs.spring.io/spring-framework/docs/4.0.x/spring-framework-reference/html/overview.html

Spring MVC(Model, View, Controller)

  • View
    보여지는 화면 (RESTApi에서는 없다?)

  • Controller
    View와 Service 사이 연결

@RestController
public class TestController {

    @GetMapping(value = "/message")
    public Object response1() {
    	return 'test';
    }
}
  • Service
    로직처리 DAO를 통해 DB와 연결

  • DAO (Data Access Object)
    데이터베이스를 연결

  • DTO (Data Transfer Object)
    데이터 교환, getter, setter 두가지만 가지고있음

  • implement (Service - Servicempl / DAO - DAOimple)
    https://velog.io/@duckchanahn/Service%EC%99%80-Serviceimpl

IoC DI

IoC (Inversion of Control)

기존 자바에서는 생성(NEW), 소멸 등 제어를 직접 진행
Spring에서는 제어를 자체적으로함

기존자바

 public class TestController {
	private TestService testService;
  	
  	public TestController() {
  		this.testService = new TestService();
  	}
  }

Spring

 public class TestController {
 	
	private TestService testService;
  	
 	@Autowired
  	public TestController(TestService testService) {
  		this.testService = testService;
  	}
  }

스프링 프로젝트에서 사용되는 객체들을 Bean으로 관리하고 @Autowired를 통해 객체를 주입해준다.

DI (Dependency Injection)

??

profile
안녕하세요.

0개의 댓글