일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
- 잡토이
- 리브레캐드
- 잡토이 메이킹 코딩 학원
- 톰캣
- 시작하기
- librecad
- 라즈베리파이
- 운정
- 아두이노
- jsp
- 코딩
- 설정
- 오라클
- Unity
- jobtoy
- MSSQL
- oracle
- Android
- 설치
- Spring Security
- 스크래치
- 파주
- 강좌
- 안드로이드
- mysql
- html5
- 유니티
- tomcat
- s4a
- 예제
- Today
- Total
랩제이
[SpringFramework] Spring 3 적용하기 본문
[SpringFramework] Spring 3 적용하기
1. 로그인
2. 게시판 리스트 보여주기
/board/boardList.do
Spring 2에서 사용하던 xml 설정을 이용하지 않습니다.
설정을 java source에서 직접 할 수 있습니다.
2.1 Controller
control 단이라는 것을 알려주기 위해서 class 선언 위에 @Controller 써줍니다.
service와 연결하기 위하여 @Autowired를 이용합니다.
ctrl 단(kr.actsoft.system.web.BoardCtrl)의 메소드에서 위에 다음처럼 선언합니다.
...
@Controller
public class BoardCtrl{
...
@Autowired
private MessageSourceAccessor messages;
@Autowired
private BoardSvc boardSvc;
...
@RequestMapping(value = "/board/boardList.do")
protected ModelAndView boardList(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
...
return new ModelAndView("board/boardList" , resultMap);
}
...
}
2.2 Service
control 단에서 페이지로 이동을 하지만
페이지로 이동하면서 필요한 데이타는 Service 단에서 요청을 하게 됩니다.
Service단은 DB와 연결을 하기 위하여 DAO단과 @Autowired 설정을 합니다.
...
@Repository("boardSvc")
public class BoardSvcImpl implements BoardSvc{
...
@Autowired
private BoardDao boardDao;
...
@Override
public Map<String, Object> findBySelectAll(Map<String, Object> condition, Integer pageIdx, Integer listCnt) throws Exception {
...
return resultMap;
}
...
2.3 Dao
DB 연결은 ibatis를 이용하게 됩니다.
@Autowired를 이용하여 연결을 해줍니다.
...
@Repository("boardDao")
public class BoardDaoImpl implements BoardDao{
@Autowired
private SqlMapClient sqlMapClient;
@Override
public List<Board> selectAll(Map<String, Object> condition, Integer pageIdx, Integer listCnt) throws Exception {
return sqlMapClient.queryForList("board.selectAll",condition, pageIdx, listCnt);
}
2.5 에서 3.0으로 변경 할 때 DB 조회하는 메소드에 대해서도 수정해야 합니다.
extends SqlMapClientDaoSupport 는 삭제합니다.
getSqlMapClientTemplate() 메소드를 sqlMapClient로 변경합니다.
2.3.1 원하는 DB로 연결하여 쿼리하기
spring 설정 파일에서 DB 연결하는 부분은 보통
<bean id="dsDefault" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
...
</bean>
...
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
...
</bean>
이것을 많이 사용합니다. ibatis와 연결하기 위해서 id를 유저가 sqlMapClient라고 지정했습니다.
spring 3.0 java 소스상에 원하는 DB와 연결된 ibatis의 쿼리를 실행하기 위해서
private SqlMapClient sqlMapClient;
SqlMapClient의 변수명을 ibatis로 설정된 bean id명으로 사용합니다.
@Autowired를 사용할 경우에 다른 곳에서 패키지가 다르더라도
클래스명이 동일하고 @Autowired를 사용했다면 오류가 발생하게 됩니다.
@Autowired는 Bean id로 등록을 시켜주는데 동일명이 등록되어서 발생 한 것으로 보입니다.
[SpringFramework] Spring 3 적용하기
'programming > spring_framework' 카테고리의 다른 글
[spring framework] Spring3에 @PathVariable 을 이용하여 REST 방식의 url을 적용 (0) | 2012.10.30 |
---|---|
spring framework tomcat 6 JNDI 연결 예제 (0) | 2012.05.08 |
스프링mvc에서 언어 변경하기 (0) | 2012.03.21 |
스프링프레임워크 버전 확인하기 (0) | 2012.03.21 |
Spring Framework 구조도 (0) | 2012.03.21 |