SpringMvc-reset風格

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

<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; }web

@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;
}
相關文章
相關標籤/搜索