美文网首页
Spring MVC 表单处理

Spring MVC 表单处理

作者: ChanHsu | 来源:发表于2017-04-28 09:43 被阅读31次

表单处理

@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";
    }

}

相关文章

网友评论

      本文标题:Spring MVC 表单处理

      本文链接:https://www.haomeiwen.com/subject/sqsozttx.html