SpringMvc-reset风格

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

转载于:https://my.oschina.net/u/3457493/blog/1623377

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值