http://www.cnblogs.com/leiOOlei/p/3658147.html

一、      通过@PathVariabl获取路径中的参数

    @RequestMapping(value="user/{id}/{name}",method=RequestMethod.GET)
public String printMessage1(@PathVariable String id,@PathVariable String name, ModelMap model) { System.out.println(id);
System.out.println(name);
model.addAttribute("message", "111111");
return "users";
}

例如,访问user/123/lei路径时,执行以上方法,其中,参数id=123,name=lei

二、      @ModelAttribute获取POST请求的FORM表单数据

JSP表单如下

<form method="post" action="hao.do">
a: <input id="a" type="text" name="a"/>
b: <input id="b" type="text" name="b"/>
<input type="submit" value="Submit" />
</form>

Java  Pojo如下

    public class Pojo{
private String a;
private int b;
}

Java Controller如下

@RequestMapping(method = RequestMethod.POST)
public String processSubmit(@ModelAttribute("pojo") Pojo pojo) { return "helloWorld";
}

三、      直接用HttpServletRequest获取

@RequestMapping(method = RequestMethod.GET)
public String get(HttpServletRequest request, HttpServletResponse response) {
System.out.println(request.getParameter("a"));
return "helloWorld";
}

四、      用注解@RequestParam绑定请求参数

用注解@RequestParam绑定请求参数a到变量a

当请求参数a不存在时会有异常发生,可以通过设置属性required=false解决,

例如: @RequestParam(value="a", required=false)

Controller如下

@RequestMapping(value = "/requestParam", method = RequestMethod.GET)
public String setupForm(@RequestParam("a") String a, ModelMap model) {
System.out.println(a);
return "helloWorld";
}

Spring3 MVC请求参数获取的几种方法[转载]的更多相关文章

  1. Spring3 MVC请求参数获取的几种方法

    Spring3 MVC请求参数获取的几种方法 一.      通过@PathVariabl获取路径中的参数 @RequestMapping(value="user/{id}/{name}&q ...

  2. Spring3 MVC请求参数获取的几种方法[转]

    Spring3 MVC请求参数获取的几种方法 Spring3 MVC请求参数获取的几种方法 一.      通过@PathVariabl获取路径中的参数 @RequestMapping(value=& ...

  3. Spring3 MVC请求参数获取的几种场景

    访问/aaa/bbb所对应的@Controller @RequestMapping("/aaa")//类级别,可以不需要,如果要了,下面所有的请求路径前都需要加入/aaa publ ...

  4. Spring MVC 的请求参数获取的几种方法

    通过@PathVariabl注解获取路径中传递参数 @RequestMapping(value = "/{id}/{str}") public ModelAndView hello ...

  5. springmvc请求参数获取的几种方法

    1.直接把表单的参数写在Controller相应的方法的形参中,适用于get方式提交,不适用于post方式提交. /** * 1.直接把表单的参数写在Controller相应的方法的形参中 * @pa ...

  6. jmeter脚本中请求参数获取的几种方式

     a.从数据库获取: 譬如接口请求参数中id的值,我需要从数据库获取,如下设置: 先设置jdbc connection configuration,然后设置JDBC b.从CSV获取: 获取CSV文件 ...

  7. 获取网页URL地址及参数等的两种方法(js和C#)

    转:获取网页URL地址及参数等的两种方法(js和C#) 一 js 先看一个示例 用javascript获取url网址信息 <script type="text/javascript&q ...

  8. Struts2获取request三种方法

    Struts2获取request三种方法   struts2里面有三种方法可以获取request,最好使用ServletRequestAware接口通过IOC机制注入Request对象. 在Actio ...

  9. Spring MVC请求参数绑定 自定义类型转化 和获取原声带额servlet request response信息

    首先还在我们的框架的基础上建立文件 在domian下建立Account实体类 import org.springframework.stereotype.Controller; import org. ...

随机推荐

  1. LSTM CNN GRU DGA比较

    测试环境:linux,8cpu核,8G内存 优化后的模型比较 模型                         速度/eps          准确率 NN                    ...

  2. 对va_list; va_start ; va_end ;vsprintf理解(转)

    以下为转载内容: int printf(const char* fmt, ...) { va_list args; int i; //1.将变参转化为字符串 va_start(args,fmt); v ...

  3. svn: E200009: 'lib/systemd/system/dropbear@.service': a peg revision is not allowed here problem

    case: svn add lib/systemd/system/dropbear@.service svn: E200009: 'lib/systemd/system/dropbear@.servi ...

  4. SQL Server 调优系列玩转篇三(利用索引提示(Hint)引导语句最大优化运行)

    前言 本篇继续玩转模块的内容,关于索引在SQL Server的位置无须多言,本篇将分析如何利用Hint引导语句充分利用索引进行运行,同样,还是希望扎实掌握前面一系列的内容,才进入本模块的内容分析. 闲 ...

  5. L1-023 输出GPLT

    给定一个长度不超过10000的.仅由英文字母构成的字符串.请将字符重新调整顺序,按GPLTGPLT....这样的顺序输出,并忽略其它字符.当然,四种字符(不区分大小写)的个数不一定是一样多的,若某种字 ...

  6. django页面导出excel

    from django.http import HttpResponse from xlwt import * from io import BytesIO def excel_export(requ ...

  7. vue 兼容360及safari的方法

    1. npm install --save-dev babel-polyfill 2.  main.js 中 import "babel-polyfill";        或者: ...

  8. 公告:《那些年,追寻Jmeter的足迹》上线

    在我们团队的努力下,我们<那些年,追寻Jmeter的足迹>手册第1版本工作完成(后面还会有第2版本),比较偏基础,这是汇集我们团队的经验和团队需要用到的知识点来整理的,在第2个版本,我们整 ...

  9. ubuntu vsftpd

    With a bit of playing around I've managed to come up with a semi solution (not perfect but good enou ...

  10. [LeetCode&Python] Problem 766. Toeplitz Matrix

    A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element. Now given ...