【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 { //访问 ...
随机推荐
- C#开发-ftp操作方法整理
1.整理简化了下C#的ftp操作,方便使用 1.支持创建多级目录 2.批量删除 3.整个目录上传 4.整个目录删除 5.整个目录下载 2.调用方法展示, var ftp ...
- vs2012新建实体数据模型(EF)时无Mysql数据源
sql转mysql数据库,用到EF,遇到vs2012新建实体数据模型时无Mysql数据源的问题. 问题截图如下: 解决方法1:(简单的的解决方法,有可能解决问题,如不能解决问题,请看解决方法2): ( ...
- Android_Dialog
layout.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xml ...
- HeaderTemplate
前台代码: <asp:Repeater ID="rptList" runat="server" onitemdatabound="doSomet ...
- linux 多核
posix threading programming beej's guide to unix ipc the gnu c library: virtual memory allocation an ...
- SpringAOP的注解方式
AOP(注解)[理解][应用][重点] 1.AOP注解配置流程 A.开启AOP配置支持注解@aspectj 核心配置文件中添加以下配置,功能等同于注解配置Bean的自动扫描路径 <aop:asp ...
- C语言进行CGI程序设计
一.CGI概述 CGI(公用网关接口)规定了Web服务器调用其他可执行程序(CGI程序)的接口协议标准.Web服务器通过调用CGI程序实现和Web浏览器的交互, 也就是CGI程序接受Web浏览器发送给 ...
- [gulp] gulp lint 忽略文件
how does the ignore parameter works in gulp and nodemon? 参考了 前端构建工具gulp入门教程,里面的lint我不需要检查所有js下面的文件,因 ...
- 【转】MyBatis学习总结(二)——使用MyBatis对表执行CRUD操作
[转]MyBatis学习总结(二)——使用MyBatis对表执行CRUD操作 上一篇博文MyBatis学习总结(一)——MyBatis快速入门中我们讲了如何使用Mybatis查询users表中的数据, ...
- ORCAL
select name from v$database;--查询当前数据库名: select instance_name from v$instance;--查询当前数据库实例名 select def ...