
*IoC를 구현하기 위해 DI가 필요하다!
-Model: 데이터 처리, 연산, 로직
-> 데이터를 가지고 연산을 하려면 데이터베이스와 소통이 필요함
->클래스: Service(로직 담당), Repository(데이터베이스와 소통 담당)
-View: 화면
-Control: Model과 View를 연결
->사용자와 Model의 중간 매개체
@Controller
@ResponseBody
public class ProductController {
//상품 조회(목적: 요청)
@RequestMapping(value="", method = RequestMethod.GET)
public String findProduct(){
return "Notebook";
}
}
@ResponseBody: 자바 객체를 json 기반의 HTTP Body로 변환
@RequestMapping: value에 url이 들어오면 get 방식으로 데이터 요청
ProductService
@Service
public class ProductService {
public String findProduct(){
return "Notebook!";
}
}
ProductController
@Controller
@ResponseBody
public class ProductController {
//상품 조회(목적: 요청)
@RequestMapping(value="", method = RequestMethod.GET)
public String findProduct(){
ProductService productService=new ProductService();
return productService.findProduct();
}
}