BACKEND/스프링 Spring
[spring3.0] 게시판 3.0 Spring Web View
꾸준히개발하자
2022. 3. 30. 01:24
프로젝트 명 : SpringWebView
템플릿 : Spring MVC Project
패키지 : com.exe.springwebview
Custom View
1. 기존방식 ModelAndView
jsp파일로 화면 띄위기
HomeController.java
@RequestMapping(value = "/simpleCustomView.action", method = RequestMethod.GET)
public ModelAndView customView() {
ModelAndView mav = new ModelAndView();
mav.setViewName("simpleCustomView");
return mav;
}
SimpleCustomView.java
클래스 파일이므로 View와 같은 역할을 하도록 만들어야 한다.
값을 여러개 넘기고 받는것이 가능하다
public class SimpleCustomView extends AbstractView {
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
HttpServletResponse response) throws Exception {
PrintWriter out = response.getWriter();
out.print("<html>");
out.print("<head>Class View");
out.print("</head>");
out.print("<body>");
out.print("<h2>");
out.print(model.get("message"));
out.print("</body>");
out.print("<html>");
}
}