>>>>>> controller
package com.controller;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import com.bean.SumDTO;
@Controller
public class SumController { //POJO형식 -> 순수한 자기만의 클래스 (extends implement 모두 안해줌)
//http://localhost:9090/Chapter06_1/input.do
// @RequestMapping(value="/input.do", method = RequestMethod.GET) // get방식
// public ModelAndView input() {
// ModelAndView mav = new ModelAndView();
// mav.setViewName("/sum/input");
// return mav;
// }
//리턴타입이 String이면 문자열이아니라 뷰이름으로 사용된다.
//뷰이름이 아니라 실제 문자열로 리턴하고 싶을때는 @ResponseBody를 사용함
@RequestMapping(value="/input.do", method = RequestMethod.GET) // get방식
public String input() {
return "/sum/input";
}
// @RequestMapping(value="/result.do", method = RequestMethod.GET) // get방식
// public ModelAndView result() {
// ModelAndView mav = new ModelAndView();
// mav.setViewName("/sum/result");
// return mav;
// }
// @RequestMapping(value="/result.do", method = RequestMethod.GET) // get방식
// public ModelAndView result(@RequestParam int x, int y) {
//
// ModelAndView mav = new ModelAndView();
// mav.addObject("x", x);
// mav.addObject("y", y);
// mav.setViewName("/sum/result");
// return mav;
// }
// @RequestMapping(value="/result.do", method = RequestMethod.GET) // get방식
// public String result(@RequestParam(required=false) String x, @RequestParam(required=false) String y, Model model) {
//
// if(x.equals("")) x="0";
// if(y.equals("")) y="0";
//
// model.addAttribute("x", Integer.parseInt(x));
// model.addAttribute("y", Integer.parseInt(y));
// return "/sum/result";
// }
// @RequestMapping(value="/result.do", method = RequestMethod.GET) // get방식
// public String result(@RequestParam Map<String, String> map, ModelMap modelMap) {
//
// modelMap.put("x", map.get("x"));
// modelMap.put("y", map.get("y"));
// return "/sum/result";
// }
//
@RequestMapping(value="/result.do", method = RequestMethod.GET) // get방식
public String result(@ModelAttribute SumDTO sumDTO, ModelMap modelMap) {
modelMap.put("sumDTO", sumDTO);
return "/sum/result";
}
}
>>>>>>>>>>>>>>> result.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%-- ${param.x } + ${param.y } = ${param.x + param.y} --%>
<%-- ${x } + ${y } = ${x+y } --%>
${sumDTO.x } + ${sumDTO.y } = ${sumDTO.x + sumDTO.y }
</body>
</html>
'JAVA 개발 공부 정보' 카테고리의 다른 글
[java-note] Chapter06_1 get-> post 방식 변경 & 한글깨짐 보완 (0) | 2018.02.22 |
---|---|
[java-note] fmt태그 사용하고 소수점 제외방법 #.## 사용 (0) | 2018.02.22 |
[java-note] Chapter06_1 x, y없을때 modelandview 간소화처리, ModelMap 처리 (0) | 2018.02.22 |
[java-note] controller 변경 (0) | 2018.02.22 |
[java-note] WAC (0) | 2018.02.22 |