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";}
查看全文
相关阅读:
Django 模版当中使用中文 UnicodeDecodeError at / 问题
sql中索引不会被用到的几种情况
Django安装
分享一个webapi接口性能测试的工具
orleans 2.0 进阶之自定义持久化储存
centos7 .net core 使用supervisor守护进程,可以后台运行
将.net core 发布到Linux上的一些坑
.net core 部署在Linux系统上运行的环境搭建总结
.net core 基于NPOI 的excel导入导出类,支持自定义导出哪些字段,和判断导入是否有失败的记录
基于Ace Admin 的菜单栏实现
原文地址:https://www.cnblogs.com/hzcya1995/p/13317960.html
最新文章
background-clip背景切割
盒模型
HTML写元素周期表
数组分析器
编程入门——工具初识、数据类型转换、数字类型
node .js 数据类型
node .js 变量
猫眼项目
符号
静态网页2
热门文章
[USACO11FEB]Generic Cow Protests
洛谷P6022 快乐水
[NOIP2016]玩具谜题
[USACO07JAN]Protecting the Flowers S
[USACO07DEC]道路建设Building Roads
AT168 自宅からの脱出
[USACO14MAR]浇地Watering the Fields
mySQL 5.7版 解决密码登录失败Access denied for user 'root'@'localhost' (us
python3全方位教程
别人的博客,挺好的
Copyright © 2011-2022 走看看