zoukankan
html css js c++ java
springMVC参数的传递方式
通过@PathVariabl注解获取路径中传递参数
JAVA
1
@RequestMapping(value
=
"
/{id}/{str}
"
)
2
public
ModelAndView helloWorld(@PathVariable String id,
3
@PathVariable String str) {
4
System.out.println(id);
5
System.out.println(str);
6
return
new
ModelAndView(
"
/helloWorld
"
);
7
}
用@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;
4
5
JAVA controller
1
@RequestMapping(method
=
RequestMethod.POST)
2
public
String processSubmit(@ModelAttribute(
"
pojo
"
) Pojo pojo) {
3
4
return
"
helloWorld
"
;
5
}
直接用HttpServletRequest获取
JAVA
1
@RequestMapping(method
=
RequestMethod.GET)
2
public
String get(HttpServletRequest request, HttpServletResponse response) {
4
System.out.println(request.getParameter(
"
a
"
));
5
return
"
helloWorld
"
;
6
}
用注解@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";}
查看全文
相关阅读:
项目启动报错:No suitable driver found for jdbc:oracle:thin:@192.168.7.146:1521:oracle
(八)Oracle学习笔记—— 触发器
(七)Oracle学习笔记—— 游标
spring自动装配(No qualifying bean )
Intellij output 中文乱码
使用Spring开发和监控线程池服务
IDEA在编辑时提示could not autowire
java 过滤器(Filter)与springMVC 拦截器(interceptor)的实现案例
Java过滤器(Filter)与SpringMVC拦截器(Interceptor)之间的关系与区别
idea 添加多模块项目
原文地址:https://www.cnblogs.com/hzcya1995/p/13317960.html
最新文章
WPF Application 类介绍以及怎样修改启动方式
C#基础知识回顾-- 反射(4)
C#基础知识回顾-- 反射(3)
Oracle字符串函数
linux、windows搭建nginx出现问题集锦
oracle 如何查看pga
c#数据库连接 出现错误提示:keyword not supported:'connection timeour'
The test form is only available for requests from the local machine.
【转】实现虚拟机VMware上linux与windows互相复制与粘贴
转: 解决【Unable to make the session state request to the session state server】
热门文章
java学习5-jar包的下载以及导入
java学习4-Maven的发布war并部署到tomcat
java学习3-Maven的使用
java学习2-webserver测试工具soapUI使用
mongodb的基本语法(二)
mongodb的基本语法(一)
Oracle中sign/decode/nvl/round/trunc/(+)/instr/substr/replace解释
proxool连接池参数解释
mongodb安装的两条命令
登录首页时报错:java.lang.IllegalArgumentException (不合法的参数异常)
Copyright © 2011-2022 走看看