SpringMVC 控制器默认支持GET和POST两种方式

在SpringMVC的controller中,@RequestMapping只写路径,不包含RequetMethod.GET和RequetMethod.POST,HttpServletRequest的getParameter(“*”)方法同时支持这两种方式。

1 @RequestMapping("savedata")
2     public @ResponseBody void savedata(HttpServletRequest req, HttpServletResponse resp) throws Exception {
3 
4         String taskClass = req.getParameter("taskclass");

ServletRequest接口中对该方法的说明如下,可以从请求字符串(URL)和POST实体(通过getInputStream和getReader方法)中读取参数:

 1 /**
 2      * Returns the value of a request parameter as a <code>String</code>,
 3      * or <code>null</code> if the parameter does not exist. Request parameters
 4      * are extra information sent with the request.  For HTTP servlets,
 5      * parameters are contained in the query string or posted form data.
 6      *
 7      * <p>You should only use this method when you are sure the
 8      * parameter has only one value. If the parameter might have
 9      * more than one value, use {@link #getParameterValues}.
10      *
11      * <p>If you use this method with a multivalued
12      * parameter, the value returned is equal to the first value
13      * in the array returned by <code>getParameterValues</code>.
14      *
15      * <p>If the parameter data was sent in the request body, such as occurs
16      * with an HTTP POST request, then reading the body directly via {@link
17      * #getInputStream} or {@link #getReader} can interfere
18      * with the execution of this method.
19      *
20      * @param name a <code>String</code> specifying the name of the parameter
21      *
22      * @return a <code>String</code> representing the single value of
23      * the parameter
24      *
25      * @see #getParameterValues
26      */
27     public String getParameter(String name);

 

 

 

参考:

http://tomcat.apache.org/tomcat-5.5-doc/servletapi/index.html

http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#mvc-ann-requestmapping

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值