16_springboot RestController返回jsp和redirect重定向问题

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");
}
posted @ 2020-11-12 15:57  脑袋有点大  阅读(310)  评论(0编辑  收藏  举报