java javabean和List存储表格数据(用List存储类)

发布时间:2020-07-15 19:46:12 作者:wx5d21d5e6e5ab1
来源:网络 阅读:586

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<User> list=new ArrayList<>();

list.add(user1);
list.add(user2);
list.add(user3);
    for(User v:list)
    {   
        System.out.println(v);
    }
Map<Integer,User> map=new HashMap<>();
map.put(1, user1);
map.put(2, user2);
map.put(3, user3);
Set<Integer> 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;
}

}

推荐阅读:
  1. java 表格数据的存储
  2. 用java实现分页查询的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

java bea ava

上一篇:以当前时间创建文件

下一篇:Exchange 虛擬環境實測

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》