表單處理
@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";
}
}
靜態(tài)頁面返回和頁面重定向
@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";
}
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者