通过@PathVariabl注解获取路径中传递参数

转载请注明出处:springmvc请求接收参数的几种方法

代码下载地址:http://www.zuida@ima@com/share/1751862044773376.htm

JAVA

  1. @RequestMapping(value= " /{id}/{str} " )
  2. public ModelAndView helloWorld(@PathVariable String id, @PathVariable String str) {
  3. System.out.println(id);
  4. System.out.println(str);
  5. return new ModelAndView( " /helloWorld " );
  6. }

用@ModelAttribute注解获取POST请求的FORM表单数据
JSP

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

JAVA pojo

  1. public class Pojo{
  2. private String a;
  3. private int b;

JAVA controller

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

直接用HttpServletRequest获取
JAVA

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

用注解@RequestParam绑定请求参数a到变量a
当请求参数a不存在时会有异常发生,可以通过设置属性required=false解决,
例如: @RequestParam(value="a", required=false)
JAVA

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

【springmvc Request】 springmvc请求接收参数的几种方法的更多相关文章

  1. springmvc请求接收参数的几种方法

    一.通过@PathVariable获取路径中的参数 @RequestMapping(value="user/{id}/{name}",method=RequestMethod.GE ...

  2. HttpServletRequest接收参数的几种方法

    HttpServletRequest接收参数的几种方法 我们经常用servlet和jsp, 经常用request.getParameter() 来得到数据. request.getParameter( ...

  3. struts2 Action 接收参数的三种方法

    刚学Struts2 时 大家可能遇到过很多问题,这里我讲一下Action 接收参数的三种方法,我曾经在这上面摔过一回.所以要警醒一下自己..... 第一种:Action里声明属性,样例:account ...

  4. ASP.NET MVC post请求接收参数的三种方式

    1.在控制器中建立一个PostDemo方法,建立视图创建一个表单 <h2>PostDemo</h2> name的值:@ViewBag.name <br /> nam ...

  5. struts2接收参数的5种方法

    以下形式中最常用的是前两种 1. 使用Action的属性: 在action 里面定义要接收的参数,并提供相应的setter,getter,和提交参数的名称一致, 并不用做数据类型的转换相应提交方式可以 ...

  6. SpringBoot Controller接收参数的几种方式盘点

    本文不再更新,可能存在内容过时的情况,实时更新请移步我的新博客:SpringBoot Controller接收参数的几种方式盘点: SpringBoot Controller接收参数的几种常用方式盘点 ...

  7. Struts2中Action接收参数的四种形式

    1.Struts2的Action接收参数的三种形式.      a. 使用Action的属性接收(直接在action中利用get方法来接收参数):                   login.js ...

  8. ssh框架总结之action接收参数的三种方式

    页面将参数传递给action的三种方式 一是通过属性传值: 将页面和action的的属性值保持一致,在action上写上该属性的set和get方法,这样在页面提交参数的时候,action就会调用set ...

  9. SpringBoot接收前端参数的三种方法

    都是以前的笔记了,有时间就整理出来了,SpringBoot接收前端参数的三种方法,首先第一种代码: @RestController public class ControllerTest { //访问 ...

随机推荐

  1. C#_数据库交互_SqlHelper

    using System; using System.Collections.Generic; using System.Text; using System.Data.SqlClient; usin ...

  2. 梭子鱼:APT攻击是一盘更大的棋吗?

    随着企业对IT的依赖越来越强,APT攻击可能会成为一种恶意打击竞争对手的手段.目前,APT攻击目标主要有政治和经济目的两大类.而出于经济目的而进行的APT攻击可以获取竞争对手的商业信息,也可使用竞争对 ...

  3. mysql数据库常用语句

    关于mysql数据库常用命令的整理: 一:对于数据库的操作 show databases;显示当前用户下所有的数据库名称 use database_name;进入当前数据库 create databa ...

  4. 关于Eclipse中的egit的常规使用和模板

    修改bug的模板 要提交的comment信息.TDI-31426 fix bug: if get studio license use : Import License :after get lice ...

  5. [转]分布式系统为什么需要 Tracing?

    分布式系统为什么需要 Tracing?   先介绍一个概念:分布式跟踪,或分布式追踪.   电商平台由数以百计的分布式服务构成,每一个请求路由过来后,会经过多个业务系统并留下足迹,并产生对各种Cach ...

  6. 在Activiti官方源码上提交的两个bugfix

    前段时间在Activiti官方源码上提交了两个bugfix,截图为证. 第1个是BPMN model输出的bug:

  7. EasyUIDataGrid 的List<T>转Json

    EasyUI的DataGrid的Json自己拼接的话非常麻烦,而且容易出错,于是写了个通用的方法! CustomList<T>自定义类,继承于List<T>,用来处理返回的实体 ...

  8. mysqlimport 导入文件到数据库命令

    mysqlimport -h 172.16.145.125 -u ocetl -pocetl test  --fields-terminated-by='|' '/home/ocetl/tmp_use ...

  9. linux运维常用命令

    1.linux启动过程 开启电源 --> BIOS开机自检 --> 引导程序lilo或grub--> 内核的引导(kernel boot)--> 执行init(rc.sysin ...

  10. [MAXscript Tool]FFX_PalyBack v1.1 ShowReel

    自己的写的一个简单的脚本方便实现大面积的烟,火,爆炸,云的效果.能实现静态动态的切换,还有快速的偏移FumeFX的缓存,支持随机缓存 具体看这个插件的ShowReel,结算的三套基础的火焰然后用此脚本 ...