1) 설정파일
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">
<context:component-scan base-package="spring.anno.board" />
</beans>
2) DTO 클래스
package spring.anno.board;
import org.springframework.stereotype.Component;
@Component // DTO 기능의 어노테이션
public class BoardDTO {
private int no = 1;
private String name = "홍길동";
private String title = "축하";
private String contents = "게시판 오픈 축하합니다.";
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getContents() {
return contents;
}
public void setContents(String contents) {
this.contents = contents;
}
}
3) 서비스 인터페이스
package spring.anno.board;
public interface BoardService {
public void insert(BoardDTO boardDTO);
}
package spring.anno.board;
public interface boardDAO {
public void insert(BoardDTO boardDTO);
}
6) DAO 클래스
package spring.anno.board;
import org.springframework.stereotype.Repository;
@Repository // DAO 기능의 어노테이션
public class BoardDAOImpl implements boardDAO {
@Override
public void insert(BoardDTO boardDTO) {
System.out.println("BoardDAO 클래스 호출");
System.out.println("===== BoardDTO =====");
System.out.print(boardDTO.getNo());
System.out.print("\t"+boardDTO.getName());
System.out.print("\t"+boardDTO.getTitle());
System.out.println("\t"+boardDTO.getContents());
System.out.println("=======================");
}
}
8) 메인
package spring.anno.board;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class BoardMain {
public static void main(String[] args) {
AbstractApplicationContext context =
new ClassPathXmlApplicationContext("board.xml");
context.registerShutdownHook();
BoardController controller =
context.getBean("boardController", BoardController.class);
BoardDTO boardDTO =
context.getBean("boardDTO", BoardDTO.class);
controller.insert(boardDTO);
context.close();
}
}
Service 클래스 호출
BoardDAO 클래스 호출
===== BoardDTO =====
1 홍길동 축하 게시판 오픈 축하합니다.
=======================
' Spring Framework' 카테고리의 다른 글
AOP 용어 및 개념 이해를 위한 예제 (0) | 2016.04.01 |
---|---|
AOP 실습 (0) | 2016.03.31 |
@Controller와 @Component (0) | 2016.03.30 |
@Resource : 이름으로 Bean을 지정하는 어노테이션 (0) | 2016.03.30 |
@Autowired : 객체를 자동으로 주입하는 어노테이션 (0) | 2016.03.30 |