和一般查询区别不同的有三个地方
1、首先是实体里面,以前存的是string 现在肯定要修改为 对象
学生类:
package bean;import java.sql.Timestamp;import java.util.Date;import baseparam.DeptBean;//存对象public class StudentBean{ private String id; private String name; private String email; private Date birthday; private DeptBean dept; public DeptBean getDept() { return dept; } public void setDept(DeptBean dept) { this.dept = dept; } public String getId() { return id; } public void setId(String id) { this.id = id; } public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { this.birthday = birthday; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public StudentBean(String name) { super(); this.name = name; } public StudentBean() { super(); } }
2、在配置文件中指定部门实体路径(/ibatis/src/SqlMapConfig.xml)
SqlMapConfig.xml文件:
3、最后一个就是修改mapper文件了(/ibatis/src/Student.xml)
Student.xml文件:
fid, fname, fbirthday insert into t_student(fid, fname, fbirthday) values ( newbosid('SFSAFSDF'), #{name, jdbcType=VARCHAR}, #{birthday} ) delete from t_student where fid = #{id} update t_student t set t.fname = #{name}, t.fbirthday = #{birthday} where t.fid = #{id}
其他地方和一般的配置一样
最后测试类
public void getAll() { StudentDao dao = new StudentDaoImpl(); Liststudents = dao.getAllStudents(); for(StudentBean c : students) { DeptBean dept = c.getDept(); System.out.println("student'id is\t" + c.getId()); System.out.println("student'name is\t" + c.getName()); if(dept != null) { System.out.println("dept'name is\t" + dept.getName()); } System.out.println("------------------------------"); } }