Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- ospf
- 정처기필기
- rinux
- Oracle
- Java
- 네트워크관리사
- NCS
- 참조타입
- VLAN
- 자바
- 원형그래프
- 리눅스
- ciscopacket
- php
- jsp연결
- 네트워크
- 정보처리기사
- html
- cisco packet
- w3school
- 버추얼머신
- sql
- 라우터
- javaee
- 오라클
- Cisco
- autoset
- 데이터베이스
- jsp
- 이것이 자바다
Archives
- Today
- Total
기록해! 정리해!
Spring MVC 구조 - ViewResolver 적용하기 본문
<?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">
<!-- HandlerMapping 등록하기 -->
<bean id="" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" >
<property name="mappings">
<props>
<prop key="/login.do">login</prop>
<prop key="/getBoardList.do">getBoardList</prop>
<prop key="/getBoard.do">getBoard</prop>
<prop key="/insertBoard.do">insertBoard</prop>
<prop key="/updateBoard.do">updateBoard</prop>
<prop key="/deleteBoard.do">deleteBoard</prop>
<prop key="/logout.do">logout</prop>
</props>
</property>
</bean>
<!-- 컨트롤 등록하기 -->
<bean id="deleteBoard" class="com.springbook.view.controller.DeleteBoardController" />
<bean id="login" class="com.springbook.view.controller.LoginController" />
<bean id="getBoardList" class="com.springbook.view.controller.GetBoardListController" />
<bean id="getBoard" class="com.springbook.view.controller.GetBoardController" />
<bean id="insertBoard" class="com.springbook.view.controller.InsertBoardController" />
<bean id="updateBoard" class="com.springbook.view.controller.UpdateBoardController" />
<bean id="logout" class="com.springbook.view.controller.LogoutController" />
<!-- ViewResolver 등록 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/board/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
[ ViewResolver 적용 하지 않는 경우는 redirect:getBoardList.do 를 붙인다. ]
package com.springbook.view.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import com.springbook.biz.board.BoardDao;
import com.springbook.biz.board.impl.BoardDaoImpl;
public class DeleteBoardController implements Controller {
public DeleteBoardController(){
System.out.println("===>DeleteBoardController");
}
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) {
System.out.println("글 삭제 처리");
int seq= Integer.parseInt(request.getParameter("seq")) ;
BoardDao dao = new BoardDaoImpl();
dao.delete(seq);
ModelAndView mav = new ModelAndView();
mav.setViewName("redirect:getBoardList.do");
return mav;
}
}
[ ViewResolver 적용 하는 경우 : 확장자를 지운다. ]
package com.springbook.view.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import com.springbook.biz.board.BoardDao;
import com.springbook.biz.board.BoardVo;
import com.springbook.biz.board.impl.BoardDaoImpl;
public class GetBoardController implements Controller {
public GetBoardController(){
System.out.println("===>GetBoardController");
}
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) {
System.out.println("글 상세 조회 처리");
int seq= Integer.parseInt(request.getParameter("seq")) ;
BoardDao dao = new BoardDaoImpl();
dao.cnt(seq);
BoardVo m = dao.getBoard(seq);
// HttpSession session = request.getSession();
// session.setAttribute("m", m);
ModelAndView mav=new ModelAndView();
mav.addObject("m", m);
mav.setViewName("getBoard");
return mav;
}
}
'Spring' 카테고리의 다른 글
어노테이션 기반 MVC 개발 - 컨트롤러 통합하기 (0) | 2022.09.26 |
---|---|
어노테이션 기반 MVC 개발 (0) | 2022.09.26 |
Spring MVC 구조 (0) | 2022.09.26 |
EL / JSTL 사용하기 (0) | 2022.09.23 |
MVC 프레임워크 구현하기 (0) | 2022.09.23 |
Comments