我为同一问题做了一个解决办法,就是创建一种新的类型来模拟通用类清单,就像我所做的那样,我创建了一种新类型,我命名为集装箱(例如:人文集装箱),其中列有我实体(个人)的清单,我使用的是清单,而不是清单类型,而且非常有效。
我举个例子, 如果能对你有用的话:
package com.dosideals.server.beans;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author LOTFI
*/
@Entity
@XmlRootElement
public class Admin implements Serializable {
@Id
private String login;
private String password;
private String firstName;
private String lastName;
public Admin() {
}
public Admin(String login, String password, String firstName, String lastName) {
this.login = login;
this.password = password;
this.firstName = firstName;
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Admin other = (Admin) obj;
if ((this.login == null) ? (other.login != null) : !this.login.equals(other.login)) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 7;
hash = 83 * hash + (this.login != null ? this.login.hashCode() : 0);
return hash;
}
@Override
public String toString() {
return "Admin{" + "login=" + login + ", password=" + password + ", firstName=" + firstName + ", lastName=" + lastName + } ;
}
}
这是集装箱管理员:
package com.dosideals.server.beans.containers;
import com.dosideals.server.beans.Admin;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author LOTFI
*/
@XmlRootElement
public class AdminContainer {
private List<Admin> admin;
public AdminContainer() {
}
public AdminContainer(List<Admin> admin) {
this.admin = admin;
}
public List<Admin> getAdmin() {
return admin;
}
public void setAdmin(List<Admin> admin) {
this.admin = admin;
}
}