堕络的小屋

  • 首页
  • 小工具
    • 百度
    • 武器库
    • 堕络的图床
    • 子域名爆破
    • 音乐搜索器
    • 手绘相片制作
    • 微博图片找博主
    • 社会主义核心价值观编码转换
  • 值得一看
    • 黄色
    • 天天优惠
    • 剑灵小助手
  • 系统
    • 高清壁纸
    • 全网优惠券
    • 付费音乐解锁
    • 自动签到框架
    • 我们的足迹系统
    • 网易云音乐签到打卡
    • 全自动网页生成系统
    • 自动采集活动线报
堕络哥哥
一个专业打杂的程序猿
  1. 首页
  2. Linux
  3. 正文

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

2017年11月16日

在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方法)中读取参数:

/**
    * Returns the value of a request parameter as a <code>String</code>,
    * or <code>null</code> if the parameter does not exist. Request parameters
    * are extra information sent with the request.  For HTTP servlets,
    * parameters are contained in the query string or posted form data.
    *
    * <p>You should only use this method when you are sure the
    * parameter has only one value. If the parameter might have
    * more than one value, use {@link #getParameterValues}.
    *
    * <p>If you use this method with a multivalued
    * parameter, the value returned is equal to the first value
    * in the array returned by <code>getParameterValues</code>.
    *
    * <p>If the parameter data was sent in the request body, such as occurs
    * with an HTTP POST request, then reading the body directly via {@link
    * #getInputStream} or {@link #getReader} can interfere
    * with the execution of this method.
    *
    * @param name a <code>String</code> specifying the name of the parameter
    *
    * @return a <code>String</code> representing the single value of
    * the parameter
    *
    * @see #getParameterValues
    */
    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

标签: Linux
最后更新:2017年11月16日

chenxing

'

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2024 堕络的小屋. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang