package com.increpas.param;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
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 vo.PersonVO;
@Controller
public class PramController {
public static final String VIEWPATH = "/WEB-INF/views/person/";
@RequestMapping("/insertForm")
public String insertForm() {
// return "person/insertForm";
return VIEWPATH + "insertForm.jsp";
}
@RequestMapping ("/insert1")
public String insert1(Model model, String name, int age, String tel) {
PersonVO vo = new PersonVO(name, age, tel);
model.addAttribute("vo", vo);
return VIEWPATH + "insertResult.jsp";
}
@RequestMapping ("/insert1")
public String insert1(Model model, @RequestParam Map<String, Object> vo) {
model.addAttribute("vo", vo);
return VIEWPATH + "insertResult.jsp";
}
/*
@RequestMapping ("/insert1/{no}")
public String insert1(Model model, @PathVariable("no") int no, String name, int age, String tel) {
PersonVO vo = new PersonVO(name, age, tel);
model.addAttribute("vo", vo);
return VIEWPATH + "insertResult.jsp";
}
*/
/*
@RequestMapping ("/insert1")
public String insert1(Model model, @RequestParam("name") String name, int age, String tel) {
PersonVO vo = new PersonVO(name, age, tel);
model.addAttribute("vo", vo);
return VIEWPATH + "insertResult.jsp";
}
*/
@RequestMapping("/insert2")
// 객체로 받는 방법
public String insert2(Model model, PersonVO vo, @RequestParam("name") String name1) {
model.addAttribute("vo", vo);
return VIEWPATH + "insertResult.jsp";
}
@RequestMapping(value={"/","/insert"}, method = RequestMethod.GET)
public String insertForm2() {
return VIEWPATH + "insertForm.jsp";
}
/*
@RequestMapping(value="/insert", method = RequestMethod.POST)
public String insert3(Model model,PersonVO vo) {
model.addAttribute("vo", vo);
return VIEWPATH + "insertResult.jsp";
}
*/
@RequestMapping(value="/insert", method = RequestMethod.POST)
public ModelAndView insert3(Model model,PersonVO vo) {
// ModelAndView : Model과 View 정보를 하나의 객체로 포장해서 전달해 주는 클래스
ModelAndView mv = new ModelAndView();
mv.setViewName(VIEWPATH + "insertREsult.jsp");
mv.addObject("vo", vo);
// model.addAttribute("vo", vo);
// return VIEWPATH + "insertResult.jsp";
return mv;
}
}
'Backend > Spring' 카테고리의 다른 글
| Spring Mybatis 기본 세팅 2 서비스 패키지, 컨트롤러 생성 (0) | 2023.05.26 |
|---|---|
| Spring Mybatis 기본 세팅 1 DB, Driver 세팅 (0) | 2023.05.23 |
| Spring 한글 필터 설정 방법 (0) | 2023.05.23 |
| Spring 기본 routine : logic Parameter 구동 방식 (0) | 2023.05.18 |
| Spring 기본 routine : logic Collection 구동 방식 (0) | 2023.05.18 |