접기
package di.main;
import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
import di.movie.dto.DirectorDTO; import di.movie.dto.MovieDTO;
public class TestMovie { public static void main(String[] args) { ApplicationContext ctx = new ClassPathXmlApplicationContext("di/movie/config/movie.xml"); MovieDTO mto = (MovieDTO)ctx.getBean("movie1"); System.out.println(mto); mto = (MovieDTO)ctx.getBean("movie2"); System.out.println(mto); mto = (MovieDTO)ctx.getBean("movie3"); System.out.println(mto); mto = (MovieDTO)ctx.getBean("movie4"); System.out.println(mto); DirectorDTO dto = (DirectorDTO)ctx.getBean("director1"); System.out.println(dto); } }
접기
접기
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans " xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance " xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd "> <bean id="movie" class="di.movie.dto.MovieDTO"/> <bean id="movie1" class="di.movie.dto.MovieDTO"> <constructor-arg> <value>0001</value> </constructor-arg> <constructor-arg> <value>나홀로집에</value> </constructor-arg> </bean> <bean id="movie2" class="di.movie.dto.MovieDTO"> <constructor-arg value="0002"/> <constructor-arg value="어벤저스"/> <constructor-arg type="double" value="60"/> </bean> <bean id="movie3" class="di.movie.dto.MovieDTO"> <constructor-arg value="0003"/> <constructor-arg value="간기남"/> <constructor-arg type="double" value="70"/> <constructor-arg value="멜로"/> <constructor-arg> <bean class="di.movie.dto.DirectorDTO"> <constructor-arg value="0001"/> <constructor-arg value="홍길동"/> <constructor-arg type="int" value="28"/> </bean> </constructor-arg> </bean> <bean id="movie4" class="di.movie.dto.MovieDTO"> <constructor-arg value="0003"/> <constructor-arg value="간기남"/> <constructor-arg type="double" value="70"/> <constructor-arg value="멜로"/> <constructor-arg ref="director1"/> </bean> <bean id="director1" class="di.movie.dto.DirectorDTO"> <constructor-arg value="d-0001"/> <constructor-arg value="임권택"/> <constructor-arg type="int" value="28"/> </bean> </beans>
접기
접기
package di.movie.dto;
public class DirectorDTO { private String directorId; private String name; private int age; public DirectorDTO(String directorId, String name, int age) { super(); this.directorId = directorId; this.name = name; this.age = age; } public DirectorDTO() { super(); } @Override public String toString() { return "DirectorDTO [directorId=" + directorId + ", name=" + name + ", age=" + age + "]"; } }
접기
접기
package di.movie.dto;
public class MovieDTO { private String movieId; private String title; private double runningTime; private String genre; private DirectorDTO director; public MovieDTO() { super(); // TODO Auto-generated constructor stub }
public MovieDTO(String movieId, String title) { super(); this.movieId = movieId; this.title = title; }
public MovieDTO(String movieId, String title, double runningTime) { super(); this.movieId = movieId; this.title = title; this.runningTime = runningTime; }
public MovieDTO(String movieId, String title, double runningTime, String genre, DirectorDTO director) { super(); this.movieId = movieId; this.title = title; this.runningTime = runningTime; this.genre = genre; this.director = director; }
@Override public String toString() { return "MovieDTO [movieId=" + movieId + ", title=" + title + ", runningTime=" + runningTime + ", genre=" + genre + ", director=" + director + "]"; } }
접기