SpringMVC 12. Redirect

About redirection

Under normal circumstances, the controller method returns a value of type string and will be treated as a logical view name

If the returned string is prefixed with forward: or redirect:, SpringMVC will treat them specially: treat forward: and redirect: as indicators, and the following strings are treated as URLs

  • redirect:success.jsp: will complete a redirection to success.jsp
  • forward:success.jsp: will complete a forwarding operation to success.jsp

E.g:

@RequestMapping(value = "/emp/{id}",method = RequestMethod.DELETE)
    public String delete(@PathVariable("id") Integer id){
        employeeDao.delete(id);
        //return "forward:/emps" ;
        return "redirect:/emps" ;
    }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325427591&siteId=291194637