通过@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. codereview介绍

    1. 定义: Code review is systematic examination (often known as peer review) of computer source code. I ...

  2. php笔记01:php基本语法格式

    1. <?php ....... ?> 2. <script laugnage="php"> ....... </script> 3. < ...

  3. Javascript之基本包装类型

    一.基本包装类型概述 var box = 'Mr. Lee';//定义一个字符串 var box2 = box.substring(2);//截掉字符串前两位 alert(box2);//输出新字符串 ...

  4. 下拉列表(web),用jQuery实现

    <!DOCTYPE html><html><head>    <meta http-equiv="Content-Type" conten ...

  5. Android_Spinner_Listener

    xml布局文件: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xml ...

  6. 如何在C#中循环一个枚举

      在C#中要想迭代循环一个枚举,最容易想到的办法是直接进行循环,如下代码所示:   public enum Suit { Spades, Hearts, Clubs, Diamonds } publ ...

  7. js动态生成按钮,页面用DIV简单布局2

    对前边不完善的修改 <!DOCTYPE html><html><head><title>test.html</title> <meta ...

  8. socket编程发送GET请求

    可以根据几根url地址,分析出主机,地址,协议等,然后用封装成的类拼接成GET请求信息,用fsockopen连接主机,进行读取操作,获取响应信息,打印 <?php //http连接接口 inte ...

  9. 20160510--hibernate懒加载问题

    懒加载 通过asm和cglib二个包实现:Domain是非final的. 1.session.load懒加载. 2.one-to-one(元素)懒加载: 必需同时满足下面三个条件时才能实现懒加载 (主 ...

  10. 2013年全国各大著名的IT公司薪资待遇大揭密

    以下为转载,特此说明!--西电好网 ============================================ 1: 本人西电通院2013届毕业硕士,根据今年找工作的情况以及身边同学的汇 ...