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.reset风格向后台发送数据的时候需要,如果是get就直接发送数据,如果是PUT、DELETE、POST的话需要以表单的形式来发送,并且在表单中需要加一个隐藏域 name为_method,value为请求方式 <form action="springmvc/testRestPost" method="post"> <input type="submit" value="提交POST"/> </form> <br/> <form action="springmvc/testRestDlete/1" method="post"> <input type="hidden" name="_method" value="DELETE"/> <input type="submit" value="提交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;
}