Spring

[이론] 1/20 목 Spring Framework - Service

PHM 2022. 1. 20. 23:36

* RestController

@Restcontroller : 메소드 모두 @ResponseBody가 디폴트로 걸린다.

 

* 리펙토링 : 코드를 만들어놓고 더 효율적으로 바꿈

	function getContextPath(){	// /myapp를 뽑아냄
	    var hostIndex=location.href.indexOf(location.host) + location.host.length;
	    var contextPath=location.href.substring(hostIndex,location.href.indexOf("/",hostIndex+1));
	    return contextPath;
 	}
    
    
    EX)  url : getContextPath() + "/boardList.do"

getContextPath() : 경로변경을 쉽게 하기 만들기위한 함수


lombok API : setter, getter method를 자동으로 만들어주는 API  

                  -> outline에 자동으로 생성

                  이클립스에게 setter, getter를 만들어 주라는 요청 / 이클립스도 lombok API를 이용해서 만들어줘야함
                   -> 이클립스와 lombok을 연동시켜야한다.

 

1. lombok dependency설정

       -> @Data 임포트 : 이클립스에게 setter, getter를 만들어 주라는 요청

 

2. lombok.jar 다운로드 

        C:\eGovFrame-3.10.0\bin\eclipse 경로에 저장

 

3. cmd창에 생성

      cd C:\eGovFrame-3.10.0\bin\jdk8u242-b08\bin

      C:\eGovFrame-3.10.0\bin\eclipse\lombok.jar

1. @data

2.
@data
@allargsconstructor : 디폴트 생성자가 안만들어짐
@noargsconstructor : 디폴트 생성자도 만들어짐

* 롬복 설치후 프로젝트 실행했을 때 에러가 난다면 maven update해보세용


 

서비스 클래스 or 비즈니스 티어 : 로직을 적어주는 클래스

                                            고객의 요구 사항을 반영하는 곳 ( 로직을 변경해주는 곳 )

                                            인터페이스에 존재하는 함수들 실행하는 곳.

 

Service도 메모리에 올려주어야한다. new BoardService();

servlet-context.xml

<context:component-scan base-package="kr.smhrd.service" />

그래서 servlet-context.xml에서 스캔해준다