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
- 참조타입
- 정처기필기
- w3school
- ciscopacket
- NCS
- 라우터
- jsp
- 이것이 자바다
- autoset
- Oracle
- javaee
- Java
- 네트워크관리사
- 오라클
- ospf
- 정보처리기사
- VLAN
- 데이터베이스
- 자바
- Cisco
- cisco packet
- 네트워크
- php
- 원형그래프
- rinux
- 리눅스
- 버추얼머신
- sql
- jsp연결
- html
Archives
- Today
- Total
기록해! 정리해!
어노테이션 기반 MVC 개발 본문
p.355
<?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.3.xsd">
<context:component-scan base-package="com.springbook.view" />
</beans>
[ 원래 소스 ]
package com.springbook.view.controller;
import java.util.List;
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 GetBoardListController implements Controller {
public GetBoardListController(){
System.out.println("===>GetBoardListController");
}
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) {
System.out.println("글 목록 검색 처리");
String searchCondition=request.getParameter("searchCondition");
String searchKeyword=request.getParameter("searchKeyword");
BoardVo vo = new BoardVo();
vo.setSearchCondition(searchCondition);
vo.setSearchKeyword(searchKeyword);
BoardDao dao = new BoardDaoImpl();
List<BoardVo> li = dao.getBoardList(vo);
// JSP 구문을 사용하려면 session 을 사용해야 한다.
// HttpSession session = request.getSession();
// session.setAttribute("li", li);
// ModelAndView 를 사용해서 mav.addObject() 넘기면
// EL / JSTL 로 받아오야 한다.
ModelAndView mav=new ModelAndView();
mav.addObject("li", li);
mav.setViewName("getBoardList");
return mav;
}
}
[ Command 화 적용 소스 ]
package com.springbook.view.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.springbook.biz.board.BoardVo;
import com.springbook.biz.board.impl.BoardDaoImpl;
@Controller
public class GetBoardListController {
public GetBoardListController(){
System.out.println("===>GetBoardListController");
}
@RequestMapping(value="/getBoardList.do")
public ModelAndView getBoardList(BoardVo vo , BoardDaoImpl dao, ModelAndView mav) {
System.out.println("글 목록 검색 처리");
mav.addObject("li", dao.getBoardList(vo));
mav.setViewName("getBoardList.jsp");
return mav;
}
}
Command 화 적용하기 전체 소스
package com.springbook.view.controller;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.springbook.biz.board.impl.BoardDaoImpl;
@Controller
public class DeleteBoardController {
public DeleteBoardController(){
System.out.println("===>DeleteBoardController");
}
@RequestMapping(value="/deleteBoard.do")
public String deleteBoard(HttpServletRequest request, BoardDaoImpl dao) {
System.out.println("글 삭제 처리");
int seq= Integer.parseInt(request.getParameter("seq")) ;
dao.delete(seq);
return "getBoardList.do";
}
}
--------------------------------------------------------------------------------------------------------------------------
package com.springbook.view.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.springbook.biz.board.BoardVo;
import com.springbook.biz.board.impl.BoardDaoImpl;
@Controller
public class InsertBoardController {
public InsertBoardController(){
System.out.println("===>InsertBoardController");
}
@RequestMapping(value="/insertBoard.do")
public String insertBoard(BoardVo vo, BoardDaoImpl dao) {
dao.insert(vo);
return "getBoardList.do";
}
}
---------------------------------------------------------------------------------------------------------------------------
package com.springbook.view.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.springbook.biz.board.BoardVo;
import com.springbook.biz.board.impl.BoardDaoImpl;
@Controller
public class UpdateBoardController {
public UpdateBoardController(){
System.out.println("===>UpdateBoardController");
}
@RequestMapping(value="/updateBoard.do")
public String handleRequest(BoardVo vo, BoardDaoImpl dao) {
dao.update(vo);
return "getBoardList.do";
}
}
------------------------------------------------------------------------------------------------------------------------------
package com.springbook.view.controller;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.springbook.biz.board.impl.BoardDaoImpl;
@Controller
public class GetBoardController {
public GetBoardController(){
System.out.println("===>GetBoardController");
}
@RequestMapping(value="/getBoard.do")
public ModelAndView getBoard(HttpServletRequest request,BoardDaoImpl dao, ModelAndView mav) {
System.out.println("글 상세 조회 처리");
int seq= Integer.parseInt(request.getParameter("seq")) ;
dao.cnt(seq);
mav.addObject("m", dao.getBoard(seq));
mav.setViewName("getBoard.jsp");
return mav;
}
}
------------------------------------------------------------------------------------------------------------------------------
package com.springbook.view.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.springbook.biz.board.BoardVo;
import com.springbook.biz.board.impl.BoardDaoImpl;
@Controller
public class GetBoardListController {
public GetBoardListController(){
System.out.println("===>GetBoardListController");
}
@RequestMapping(value="/getBoardList.do")
public ModelAndView getBoardList(BoardVo vo , BoardDaoImpl dao, ModelAndView mav) {
System.out.println("글 목록 검색 처리");
mav.addObject("li", dao.getBoardList(vo));
mav.setViewName("getBoardList.jsp");
return mav;
}
}
----------------------------------------------------------------------------------------------------------------------------
package com.springbook.view.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.springbook.biz.user.UserVo;
import com.springbook.biz.user.impl.UserDao3;
@Controller
public class LoginController {
public LoginController(){
System.out.println("===>LoginController");
}
@RequestMapping(value="/login.do")
public String login(UserVo vo, UserDao3 service ) {
System.out.println("로그인 처리");
if(service.getUser(vo) != null){
return "getBoardList.do" ;
}else{
return"login.jsp" ;
}
}
}
--------------------------------------------------------------------------------------------------------------------------
package com.springbook.view.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class LogoutController {
public LogoutController(){
System.out.println("===>LogoutController");
}
@RequestMapping(value="/logout.do")
public String logout( HttpSession session) {
System.out.println("로그아웃 처리");
session.invalidate();
return "login.jsp";
}
}
'Spring' 카테고리의 다른 글
어노테이션 기반 MVC 개발 - 요청 방식에 따른 처리 ( method 속성, vo 값 리턴 받기 ) (0) | 2022.09.26 |
---|---|
어노테이션 기반 MVC 개발 - 컨트롤러 통합하기 (0) | 2022.09.26 |
Spring MVC 구조 - ViewResolver 적용하기 (0) | 2022.09.26 |
Spring MVC 구조 (0) | 2022.09.26 |
EL / JSTL 사용하기 (0) | 2022.09.23 |
Comments