1.定义一个简单的类 User.java

public class User {

    private Integer id;
private String name; public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
}

2.前端页面代码:

·   <form action="/user.front" method="post">
<span>姓名1:</span><input type="text" name="name"/> <span>姓名2:</span><input type="text" name="name"/>
<input type="submit" value="submit"/>
</form>

3.提交时两个name需要作为数组当做参数传递.后台接收时需要做个处理:

  • 新建一个类UserModel,代码如下:
public class UserModel {

    private List<User> users;

    public UserModel(List<User> users) {
this.users = users;
} public UserModel (){} public List<User> getUsers() {
return users;
} public void setUsers(List<User> users) {
this.users = users;
}
}

4.此时前端代码name命名需改为

    <form action="/user.front" method="post">
<span>姓名1:</span><input type="text" name="users[0].name"/> <span>姓名2:</span><input type="text" name="users[1].name"/>
<input type="submit" value="submit"/>
</form>

注意name中的users已UserModel.java的变量名一致;

5.UserController接收方式为:

    @RequestMapping("user.front")
@ResponseBody
public int test(UserModel user){
System.out.println("user = " + user);;
return 1;
}

此时的参数名就是UserModel,就能成功接收到数据;

Spring Mvc 页面传递数组到后台接收的更多相关文章

  1. ajax 传递数组类型参数后台接收不到的问题

    在做排序功能的时候需要将一个数组的数据传递到后台,(当时怎么没用json,如果用json就没有那么多的事情了),数据提交采用ajax! 先看代码 js: submitbtn: function () ...

  2. ajax传递数组及后台接收

    ajax传递的是{"items":arr},其中arr=[]; 在后台String[] items=req.getParameterValues("items" ...

  3. ajax传递数组,后台接收为null解决方法

    traditional:true,加上这个就好,默认为false,即允许深度序列化参数,但是servlet api不支持,所有设为true阻止就好了. $.ajax({ type:'post', ur ...

  4. Spring MVC页面重定向

    以下示例显示如何编写一个简单的基于Web的重定向应用程序,这个应用程序使用重定向将http请求传输到另一个页面. 基于Spring MVC - Hello World实例章节中代码,创建创建一个名称为 ...

  5. spring mvc 如何传递集合参数(list,数组)

    spring mvc 可以自动的帮你封装参数成为对象,不用自己手动的通过request一个一个的获取参数,但是这样自动的参数封装碰碰到了集合参数可能就需要点小技巧才可以了. 一.基础类型和引用类型有什 ...

  6. Spring MVC 页面跳转时传递参数

    页面仍然使用 JSP,在跳转时如果想传递参数则需要用到类 RedirectAttributes. 首先看看如何打开一个普通页面: // 登录页面(每个页面都要独立的 Action 来支持其呈现) @R ...

  7. 前端AJAX传递数组给Springmvc接收处理

    前端传递数组后端(Spring)来接收并处理: <!DOCTYPE html> <html> <head> <meta charset="UTF-8 ...

  8. ajax传递数组到后台

    //实体类 public class Person { private int ID{get;set;} private string Name{get;set;} private int Age{g ...

  9. spring MVC页面的重定向

    如图,一个jsp页面跳转到下一个jsp页面通常需要上一个页面发出带有参数得请求,我们都知道spring MVC是不能直接跳页面的. 需要配置视图解析器,通过返回视图名再跳转到相应得JSP页面. 即使这 ...

随机推荐

  1. 【2】JVM-JAVA对象的访问

    Java中对象的访问 JAVA是面向对象的语言,那么在JAVA虚拟机中,存在非常多的对象,对象访问是无处不在的.即时是最简单的访问,也会涉及到JAVA栈.JAVA堆.方法区这三个非常重要的内存区域之间 ...

  2. python 进行后端分页详细代码

    后端分页 两个接口 思路: 1. 先得到最大页和最小页数(1, 20) --> 传递给前端, 这样前端就可以知道有多少个页数 2. 通过传递页数得到当前页对应数据库的最大值和最小值 3. 通过s ...

  3. SpagoBI 教程 Lesson 3: Highchart Dashboards

    SpagoBI Lesson 3: Highchart Dashboards Business Intelligence dashboards Every car comes with a dash ...

  4. VUE系列三:实现跨域请求(fetch/axios/proxytable)

    1. 在 config/index.js 配置文件中配置proxyTable 'use strict' // Template version: 1.3.1 // see http://vuejs-t ...

  5. e782. 排列JList中的项

    By default, the items in a list are arranged vertically, in a single column, as in: item1 item2 ... ...

  6. e856. 列出一个组件的所有事件

    This example demonstrates how to list all the actions in a component. ActionMap map = component.getA ...

  7. windows下docker使用及注意事项

    1.windows container模式下,pull镜像会失败 no matching manifest for windows/amd64 in the manifest list entries ...

  8. Lemon OA第1篇:简单介绍

    官方网站:http://www.mossle.com/ 声明:我不是Lemon OA作者,只是分享好的资源.以下内容均代表个人见解~ 从官网说起 知道Lemon OA,也是最近研究Activiti,看 ...

  9. git fetch , git pull

    要讲清楚git fetch,git pull,必须要附加讲清楚git remote,git merge .远程repo, branch . commit-id 以及 FETCH_HEAD. 1. [g ...

  10. 【翻译自mos文章】在RHEL7/OL7上安装Oracle 12.1.0.2的server端或者client时,报须要&quot;compat-libstdc++&quot;包

    在RHEL7/OL7上安装Oracle 12.1.0.2的server端或者client时,报须要"compat-libstdc++"包 来源于: Installation of ...