JAva javabeanとListはテーブルデータを格納する(Listでクラスを格納する)
2627 ワード
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;
}
}
考え方:リストでクラス、クラスを保存してデータを保存する
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;
}
}