成都网站建设设计

将想法与焦点和您一起共享

javajavabean和List存储表格数据(用List存储类)-创新互联

javabean
一个具有完整的set和get方法,还有一个空构造器的类

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:国际域名空间、网页空间、营销软件、网站建设、海陵网站维护、网站推广。
class User{
    private int id;
    private double salary;
    private String name;
    private String hiredate;
    public User()
    {

}

public User(int id, double salary, String name, String hiredate) {
    super();
    this.id = id;
    this.salary = salary;
    this.name = name;
    this.hiredate = hiredate;
}

public int getId() {
    return id;
}
public void setId(int id) {
    this.id = id;
}
public double getSalary() {
    return salary;
}
public void setSalary(double salary) {
    this.salary = salary;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public String getHiredate() {
    return hiredate;
}
public void setHiredate(String hiredate) {
    this.hiredate = hiredate;
}

public String toString()
{
    return "id:"+id+"salary:"+salary+"name:"+name+"hiredate:"+hiredate;
}

}

思路:用List来存储类,类来存储数据

public  class test {

//表格每一行用Map来存储,整个表格用list来存储,即List内存的是Map
public static void main(String[]args)
{

User user1=new User(1001,11,"张三","2018.5.5");
User user2=new User(1002,10,"张三2","2018.5.52");
User user3=new User(1003,9,"张三3","2018.5.53");
List list=new ArrayList<>();

list.add(user1);
list.add(user2);
list.add(user3);
    for(User v:list)
    {   
        System.out.println(v);
    }
Map map=new HashMap<>();
map.put(1, user1);
map.put(2, user2);
map.put(3, user3);
Set key=map.keySet();
for(Integer i:key)
{
    System.out.println(map.get(i));
}
}

}

//完整的javabean要有完整的set和get方法,还要有空的构造器
class User{
private int id;
private double salary;
private String name;
private String hiredate;
public User()
{

}

public User(int id, double salary, String name, String hiredate) {
    super();
    this.id = id;
    this.salary = salary;
    this.name = name;
    this.hiredate = hiredate;
}

public int getId() {
    return id;
}
public void setId(int id) {
    this.id = id;
}
public double getSalary() {
    return salary;
}
public void setSalary(double salary) {
    this.salary = salary;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public String getHiredate() {
    return hiredate;
}
public void setHiredate(String hiredate) {
    this.hiredate = hiredate;
}

public String toString()
{
    return "id:"+id+"salary:"+salary+"name:"+name+"hiredate:"+hiredate;
}

}

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前名称:javajavabean和List存储表格数据(用List存储类)-创新互联
网页链接:http://chengdu.cdxwcx.cn/article/ddiedc.html