Spring MVC 表单处理

2017-04-28  本文已影响31人  ChanHsu

表单处理

@Controller
public class StudentController {

    @RequestMapping(value = "/student",method = RequestMethod.GET)
    public ModelAndView student() {
        return new ModelAndView("student","command",new Student());
    }

    @RequestMapping(value = "/addStudent",method = RequestMethod.POST)
    public String addStudent(@ModelAttribute("SpringWeb")Student student, ModelMap modelMap) {
        modelMap.addAttribute("name",student.getName());
        modelMap.addAttribute("age",student.getAge());
        modelMap.addAttribute("id",student.getId());


        return "result";
    }
}

静态页面返回和页面重定向

@Controller
public class WebController {

    @RequestMapping(value = "/index",method = RequestMethod.GET)
    public String index() {
        return "index";
    }

    @RequestMapping(value = "/staticPage",method = RequestMethod.GET)
    public String staticPage() {
        return "redirect:/static/final.html";
    }

    @RequestMapping(value = "/redirect", method = RequestMethod.GET)
    public String redirect() {

        return "redirect:finalPage";
    }
    @RequestMapping(value = "/finalPage", method = RequestMethod.GET)
    public String finalPage() {
        return "final";
    }

}
上一篇 下一篇

猜你喜欢

热点阅读