Spring接收List型参数
第一种形式:
提交的数据形式:id=1,2,3 --> urlEncoding --> id=1%2C2%2C3
<form method="post" action="http://localhost/ExamOnline/page/test/list2">
id<input type="text" name="id"><br/>
id<input type="text" name="id"><br/>
id<input type="text" name="id"><br/>
<input type="submit">
</form>
服务器可以对其进行接收用List或者字符串(List接收时,@RequestParam("id") 必不可少,不然报错)
List接收:
@RequestMapping("/test/list1")
@ResponseBody
public String testlist(@RequestParam("id") List<Integer> ids) {
for (Integer integer : ids) {
System.out.println(integer);
}
return "ok";
}
字符串接收:
@RequestMapping("/test/list2")
@ResponseBody
public String testlist(String id) {
System.out.println(id);
return "ok";
}
第二种形式:
提交数据格式:ques[0].id=1&ques[0].title=1&ques[1].id=2&ques[1].id=2 --> UrlEncoding转码 --> 省略
表单:
<form method="post" action="http://localhost/ExamOnline/page/test/list3">
id<input type="text" name="ques[0].id"><br/>
name<input type="text" name="stu[0].title"><br/>
id<input type="text" name="ques[1].id"><br/>
name<input type="text" name="stu[1].title"><br/>
id<input type="text" name="ques[2].id"><br/>
name<input type="text" name="stu[2].title"><br/>
<input type="submit">
</form>
后台:通过一个Bean封装进去
@RequestMapping("/test/list3")
@ResponseBody
public String testpojolist(RequestModel bean) {
for (Question q : bean.getQues()) {
System.out.println(q.getTitle());
}
return "ok";
}
//get、set函数必不可少,反射必用
public class RequestModel { private List<Question> ques;
public List<Question> getQues() {
return ques;
}
public void setQues(List<Question> ques) {
this.ques = ques;
} }
第三种形式:
前台提交json格式的数据,后台使用@RequestBody List<XX> 接收即可,js转换json数据不太方便,省略
Spring接收List型参数的更多相关文章
- spring mvc 对象型参数的传递(遇到坑了)
直接来个列子: 这里设置了,contenType="application/json" 这里post 接收的参数对象. 但是问题来了: <html> <head& ...
- Spring接收web请求参数的几种方式
1 查询参数 请求格式:url?参数1=值1&参数2=值2...同时适用于GET和POST方式spring处理查询参数的方法又有几种写法: 方法一:方法参数名即为请求参数名 // 查询参数1 ...
- springmvc接收List型参数长度
springmvc默认接收list参数长度为256,过长则报越界异常,添加 @InitBinder public void initBinder(WebDataBinder binder) { // ...
- Spring MVC在接收复杂集合参数
Spring MVC在接收集合请求参数时,需要在Controller方法的集合参数里前添加@RequestBody,而@RequestBody默认接收的enctype (MIME编码)是applica ...
- 【spring mvc】spring mvc POST方式接收单个字符串参数,不加注解,接收到的值为null,加上@RequestBody,接收到{"uid":"品牌分类大”},加上@RequestParam报错 ---- GET方式接收单个参数的方法
spring mvc POST方式 接收单个参数,不加任何注解,参数名对应,接收到的值为null spring mvc POST方式 接收单个参数,加上@RequestBody,接收到参数格式:{&q ...
- Spring Boot程序接收命令行参数
Spring Boot程序接收命令行参数 输入一行,回车,触发一次.如果想要调用service层,也是可以,能调用service层,就可以做很多事,触发一次就好比调用了一次http接口一样 packa ...
- spring接收参数
public class LogonModel { private String UserName; private String Password; public String getUserNam ...
- 【spring】spring boot中使用@EnableTransactionManagement 以后,spring mvc接收前台ajax的post方法传过来的参数,使用@RequestBody接收不到参数
在启动类上添加了注解: @EnableTransactionManagement, postMan测试接口,以这种方式传递参数: 测试结果: 接收不到参数 问题解决: 原因:是因为 这个项目中的Con ...
- SpringMVC接收复杂集合参数
Spring MVC在接收集合请求参数时,需要在Controller方法的集合参数里前添加@RequestBody,而@RequestBody默认接收的enctype (MIME编码)是applica ...
随机推荐
- c# 将json转换为DataTable
/// <summary> /// 将json转换为DataTable /// </summary> /// <param name="strJson" ...
- Windows系统版本判定那些事儿[转]
Windows系统版本判定那些事儿 转自CSDN,原文链接,我比较不要脸, 全部给复制过来了 前言 本文并不是讨论Windows操作系统的版本来历和特点,也不是讨论为什么没有Win9,而是从程序员角度 ...
- hbuilder h5 原生socket
在网上搜索了很多资料都不行,要么就是不能发送数据,要么就不能接收数据,使用如下的方法可以接收数据,一个一个字节接收: 有部分限制是需要明确知道要接收多少个字节,否则容易出现接收异常.. var tes ...
- angular 基本依赖注入
import { Injectable } from '@angular/core'; @Injectable() export class ProductServiceService { const ...
- WebStrom常用快捷键
查找替换 ctrl+shift+N 通过文件名快速查找工程内的文件(必记) ctrl+shift+alt+N 通过一个字符快速查找位置(必记) ctrl+F 在文件内快速查找代码 ctrl+R ...
- 钩子(hook)编程
一.钩子介绍 1.1钩子的实现机制 钩子英文名叫Hook,是一种截获windows系统中某应用程序或者所有进程的消息的一种技术.下图是windows应用程序传递消息的过程: 如在键盘中按下一键,操作系 ...
- Invalid App Store Icon. The App Store Icon in the asset catalog in 'xxx.app' can’t be transparent nor contain an alpha channel.
1.向appstore上传应用的时候,报了这样一个错误 ERROR ITMS-90717: "Invalid App Store Icon. The App Store Icon in th ...
- 期待suqingnian.h
不定期更新,跟着自己的进度走的. 有什么好的东西可以收录的尽管留言 UPD:话说真的没人发现本宝宝的$Martix$类的$operator$打错了么?$qwq$ $2018.7.19$ /*by Qi ...
- [Swift实际操作]九、完整实例-(2)在Xcode 10中创建新项目
本文将在Xcode中创建上一文<在iTunesConnect网站中创建产品>在iTunes Connect创建的产品具有相同的Bundle ID的应用程序. 在项目模板窗口中,选择单视图模 ...
- Windows NLB搭配IIS的ARR搭建高可用环境(转载)
原文地址:http://www.cnblogs.com/shanyou/archive/2010/04/28/1723276.html 在现行的许多网络应用中,有时一台服务器往往不能满足客户端的要求, ...