两种方法来创建一个记录;
一个对象对应一条记录
一个类对应一个表结构
以后遇到表这种情况可以采用下列两种办法
1创建一个类,new 对象 再放到List容器里面
2直接将他数据放到map键值对里面,再放到List容器里面
public class MapList {
public static void main(String[] args) {
Map map=new HashMap();
map.put("name", "陈");
map.put("id",3301);
List list=new ArrayList();
list.add(map);
}
<pre name="code" class="java">package com.chenfeng;
public class Student {
private String name;
private String id;
private char sex;
public Student(String name, String id, char sex) {
super();
this.name = name;
this.id = id;
this.sex = sex;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
}
package com.chenfeng;
import java.util.ArrayList;
import java.util.List;
public class Test001 {
public static void main(String[] args) {
Student a=new Student("陈","3301",'男');
Student b=new Student("梁","332",'女');
List<Student> list=new ArrayList<Student>();
list.add(a);
list.add(b);
}
}
}