jsp传递list对象到后台

1.jsp页面

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>




test here




 
 


 
 



2. 创建两个对象

(1)

package com.lucene.model;


public class User {
private Integer id;
private String username;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}

(2)

package com.lucene.model;


import java.util.List;


public class UserModel {
private List users;


public List getUsers() {
return users;
}


public void setUsers(List users) {
this.users = users;
}
}

3.创建控制器

@RequestMapping(value = "/testAdd", method ={RequestMethod.POST})
public String testAdd(UserModel userModel) {
return "test";
}

4.关键点,list 必须是在一个对象里面,然后users[0].username的users 就是对象里面的list的变量。


你可能感兴趣的:(java,jsp,对象)