-
[Spring] 값 형식 DI프로그래밍 공부/Spring 2021. 4. 29. 23:04
뉴렉처 강사님의 동영상 강의를 정리한 글입니다.
이전 글에는 setter에 reference를 넘겨주는 것을 하였다.
(예시: XML 파일에서 선언한 exam 객체를 GridExamConsole에 DI)
이번에는 값 형식을 DI 하는 것을 배워보자
(예시: 국어, 수학, 영어, 컴퓨터 점수를 XML 파일을 이용하여 set 하는 법)
name, value 필드를 채운 property 태그를 추가한다.
value를 따른 태그로 분리하여 사용할 수도 있다.
<bean id="exam" class="spring.di.entity.NewlecExam"> <property name="kor" value="20"></property> <property name="eng" value="30"></property> <property name="math" value="50"></property> <property name="com"> <value>40</value> </property> </bean>
NewlecExam 클래스에 각 property를 setting 할 수 있는 setter 함수가 정의되어 있어야 한다.
source > generator 를 이용하여 편리하게 setter 함수를 추가하자.
값을 지정해준 뒤 실행하면 값이 들어온 것을 확인할 수 있다.
'프로그래밍 공부 > Spring' 카테고리의 다른 글
[Spring] 콜렉션 생성과 DI (0) 2021.04.30 [Spring] 생성자 DI (0) 2021.04.29 [Spring] IoC 컨테이너 사용하기 (ApplicationContext 이용하기) (0) 2021.04.29 [Spring] 스프링 DI 지시서 작성하기 (Spring Bean Configuration) (0) 2021.04.29 [JAVA] Dependency를 직접 Injection 하기 (0) 2021.04.28