RestController返回jsp,以及重定向问题
1.@Controller下
@PostMapping("/listStudents")
public String addStudent(Student s) throws Exception{
studentMapper.save(s);
return "redirect:/listStudents";
}
2.@RestController
@PostMapping("/listStudents")
public void addStudent(Student s, HttpServletResponse response) throws Exception{
studentMapper.save(s);
response.sendRedirect("listStudents");
}
ps.如果是restful风格,修改功能注意要加上..
@PutMapping("/listStudents/{stuId}")
public void updateStudent(Student s, HttpServletResponse response) throws Exception {
studentMapper.update(s);
response.sendRedirect("../listStudents");
}