java存储表

来源:互联网 发布:网络扫描器是什么 编辑:程序博客网 时间:2024/06/07 04:02
package Collection;


import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


public class Employee {


private int id;
private String name;
private int salary;
private String department;
private Date hireDate;


public Employee(int id, String name, int salary, String department, String hireDate) {
super();
this.id = id;
this.name = name;
this.salary = salary;
this.department = department;


DateFormat format = new SimpleDateFormat("yyyy-MM");
try {
this.hireDate = format.parse(hireDate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}










public void setName(String name) {
this.name = name;
}




public String getName() {
// TODO Auto-generated method stub
return name;
}













}


package Collection;


import java.util.List;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
//一个类对应一个表结构,一行对象对应一条记录
public class Test01 {


public static void main(String[] args) throws ParseException {


Employee e = new Employee(0301,"xiaofei",3000,"项目部","2000-10");
Employee e2 = new Employee(0302,"xiaoyan",4000,"xiangmu","2017-11");
Employee e3 = new Employee(0303,"wangqi",5000,"nihao","2018-15-9");

List<Employee> list = new ArrayList<Employee>();
list.add(e);
list.add(e2);
list.add(e3);

printEmpName(list);



}
public static void printEmpName(List<Employee> list){
for(int i = 0;i< list.size();i++){
System.out.println(list.get(i).getName());
}
}
}


原创粉丝点击