SpringMvc中,RequestMethod可以同时支持POST GET访问么?



开源中国众包“找人”全新改版上线 -- 入驻众包人才库,领开源礼品>>> »  

springmvc中,可以用ReuqestMethod属性来控制 POST 或 GET 方式提交表单 或访问url,

?
1
2
3
//如: 仅GET方式
 
@RequestMapping (value = "hello" ,params = "what" ,method =RequestMethod.GET)

?
1
2
3
//如: 仅POST方式
 
@RequestMapping (value = "hello" ,params = "what" ,method =RequestMethod.POST)

以上都可以正常工作但是我如果想要同时支持POST和GET,有看到如下写法:

?
1
@RequestMapping (value = "hello" ,params = "what" ,method ={RequestMethod.POST,RequestMethod.GET})

但是亲测,却报错了,说:

?
1
2
org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver.handleHttpRequestMethodNotSupported(DefaultHandlerExceptionResolver.java: 183 ) org.springframework.web.servlet.PageNotFound
WARN: Request method 'POST' not supported

还有一个疑问就是,如果不写默认是仅支持GET ?仅支持POST?还是既支持GET又支持POST?

?
1
@RequestMapping (value = "hello" ,params = "what" )
我觉得貌似是仅支持GET

孤单时会想你 孤单时会想你
发帖于 3年前
11回/33005阅

按票数排序  显示最新答案  共有11个答案 (最后回答: 3年前 )

开源中国众包“找人”全新改版上线 -- 入驻众包人才库,领开源礼品>>> »  

springmvc中,可以用ReuqestMethod属性来控制 POST 或 GET 方式提交表单 或访问url,

?
1
2
3
//如: 仅GET方式
 
@RequestMapping (value = "hello" ,params = "what" ,method =RequestMethod.GET)

?
1
2
3
//如: 仅POST方式
 
@RequestMapping (value = "hello" ,params = "what" ,method =RequestMethod.POST)

以上都可以正常工作但是我如果想要同时支持POST和GET,有看到如下写法:

?
1
@RequestMapping (value = "hello" ,params = "what" ,method ={RequestMethod.POST,RequestMethod.GET})

但是亲测,却报错了,说:

?
1
2
org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver.handleHttpRequestMethodNotSupported(DefaultHandlerExceptionResolver.java: 183 ) org.springframework.web.servlet.PageNotFound
WARN: Request method 'POST' not supported

还有一个疑问就是,如果不写默认是仅支持GET ?仅支持POST?还是既支持GET又支持POST?

?
1
@RequestMapping (value = "hello" ,params = "what" )
我觉得貌似是仅支持GET

孤单时会想你 孤单时会想你
发帖于 3年前
11回/33005阅

按票数排序  显示最新答案  共有11个答案 (最后回答: 3年前 )

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值