SpringMvc-reset style

1.需要在web.xml中配置一个filter <filter>   <filter-name>HiddenHttpMethodFilter</filter-name>   <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> </filter>

<filter-mapping> <filter-name>HiddenHttpMethodFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> 2. The reset style is required when sending data to the background, if yes get sends the data directly. If it is PUT, DELETE, or POST, it needs to be sent in the form of a form, and a hidden field name is _method in the form, and the value is the request method <form action="springmvc/testRestPost" method ="post"> <input type="submit" value="Submit POST"/> </form> <br/> <form action="springmvc/testRestDlete/1" method="post"> <input type=" hidden" name="_method" value="DELETE"/> <input type="submit" value="Submit DELETE"/> </form> <br/> <form action="springmvc/testRestPut/1" method= "post"> <input type="hidden" name="_method" value="PUT"/><input type="submit" value="提交PUT"/> </form> 3.GET、DELETE、PUT通过注解@PathVariable来接收参数 @RequestMapping(value="/testRestGet/{id}",method=RequestMethod.GET) public String testRestGet(@PathVariable String id){ return SUCCESS; }

@RequestMapping(value="/testRestPost",method=RequestMethod.POST)
public String testRestPost(){
    return SUCCESS;
}

@RequestMapping(value="/testRestDlete/{id}",method=RequestMethod.DELETE)
public String testRestDlete(@PathVariable String id){
    return SUCCESS;
}

@RequestMapping(value="/testRestPut/{id}",method=RequestMethod.PUT)
public String testRestPut(@PathVariable String id){
    return SUCCESS;
}
@RequestMapping("/toJfDynamicDetail{id}.html")
public ModelAndView testPathVariable(@PathVariable("id") Long rowId, HttpServletRequest request) {
    ModelAndView mv = new ModelAndView();
    request.setAttribute("flag", 10);
    MarketingNotice marketingNotice = this.noticeService.findByPK(rowId);
    mv.addObject("marketingNotice", marketingNotice);
        List<MarketingNotice>  marketingNoticeList = noticeService.findPageByLatey();
        mv.addObject("marketingNoticeList", marketingNoticeList);
        mv.setViewName("dynamicDetail");
    return mv;
}

Guess you like

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