【springmvc Request】 springmvc请求接收参数的几种方法
通过@PathVariabl注解获取路径中传递参数
转载请注明出处:springmvc请求接收参数的几种方法
代码下载地址:http://www.zuida@ima@com/share/1751862044773376.htm
JAVA
- @RequestMapping(value= " /{id}/{str} " )
- public ModelAndView helloWorld(@PathVariable String id, @PathVariable String str) {
- System.out.println(id);
- System.out.println(str);
- return new ModelAndView( " /helloWorld " );
- }
用@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获取
JAVA
- @RequestMapping(method= RequestMethod.GET)
- public String get(HttpServletRequest request, HttpServletResponse response) {
- System.out.println(request.getParameter( " a " ));
- return " helloWorld " ;
- }
用注解@RequestParam绑定请求参数a到变量a
当请求参数a不存在时会有异常发生,可以通过设置属性required=false解决,
例如: @RequestParam(value="a", required=false)
JAVA
- @RequestMapping(value= " /requestParam " , method= RequestMethod.GET)
- public String setupForm(@RequestParam( " a " ) String a, ModelMap model) {
- System.out.println(a);
- return " helloWorld " ;}
【springmvc Request】 springmvc请求接收参数的几种方法的更多相关文章
- springmvc请求接收参数的几种方法
一.通过@PathVariable获取路径中的参数 @RequestMapping(value="user/{id}/{name}",method=RequestMethod.GE ...
- HttpServletRequest接收参数的几种方法
HttpServletRequest接收参数的几种方法 我们经常用servlet和jsp, 经常用request.getParameter() 来得到数据. request.getParameter( ...
- struts2 Action 接收参数的三种方法
刚学Struts2 时 大家可能遇到过很多问题,这里我讲一下Action 接收参数的三种方法,我曾经在这上面摔过一回.所以要警醒一下自己..... 第一种:Action里声明属性,样例:account ...
- ASP.NET MVC post请求接收参数的三种方式
1.在控制器中建立一个PostDemo方法,建立视图创建一个表单 <h2>PostDemo</h2> name的值:@ViewBag.name <br /> nam ...
- struts2接收参数的5种方法
以下形式中最常用的是前两种 1. 使用Action的属性: 在action 里面定义要接收的参数,并提供相应的setter,getter,和提交参数的名称一致, 并不用做数据类型的转换相应提交方式可以 ...
- SpringBoot Controller接收参数的几种方式盘点
本文不再更新,可能存在内容过时的情况,实时更新请移步我的新博客:SpringBoot Controller接收参数的几种方式盘点: SpringBoot Controller接收参数的几种常用方式盘点 ...
- Struts2中Action接收参数的四种形式
1.Struts2的Action接收参数的三种形式. a. 使用Action的属性接收(直接在action中利用get方法来接收参数): login.js ...
- ssh框架总结之action接收参数的三种方式
页面将参数传递给action的三种方式 一是通过属性传值: 将页面和action的的属性值保持一致,在action上写上该属性的set和get方法,这样在页面提交参数的时候,action就会调用set ...
- SpringBoot接收前端参数的三种方法
都是以前的笔记了,有时间就整理出来了,SpringBoot接收前端参数的三种方法,首先第一种代码: @RestController public class ControllerTest { //访问 ...
随机推荐
- codereview介绍
1. 定义: Code review is systematic examination (often known as peer review) of computer source code. I ...
- php笔记01:php基本语法格式
1. <?php ....... ?> 2. <script laugnage="php"> ....... </script> 3. < ...
- Javascript之基本包装类型
一.基本包装类型概述 var box = 'Mr. Lee';//定义一个字符串 var box2 = box.substring(2);//截掉字符串前两位 alert(box2);//输出新字符串 ...
- 下拉列表(web),用jQuery实现
<!DOCTYPE html><html><head> <meta http-equiv="Content-Type" conten ...
- Android_Spinner_Listener
xml布局文件: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xml ...
- 如何在C#中循环一个枚举
在C#中要想迭代循环一个枚举,最容易想到的办法是直接进行循环,如下代码所示: public enum Suit { Spades, Hearts, Clubs, Diamonds } publ ...
- js动态生成按钮,页面用DIV简单布局2
对前边不完善的修改 <!DOCTYPE html><html><head><title>test.html</title> <meta ...
- socket编程发送GET请求
可以根据几根url地址,分析出主机,地址,协议等,然后用封装成的类拼接成GET请求信息,用fsockopen连接主机,进行读取操作,获取响应信息,打印 <?php //http连接接口 inte ...
- 20160510--hibernate懒加载问题
懒加载 通过asm和cglib二个包实现:Domain是非final的. 1.session.load懒加载. 2.one-to-one(元素)懒加载: 必需同时满足下面三个条件时才能实现懒加载 (主 ...
- 2013年全国各大著名的IT公司薪资待遇大揭密
以下为转载,特此说明!--西电好网 ============================================ 1: 本人西电通院2013届毕业硕士,根据今年找工作的情况以及身边同学的汇 ...