package com.lbx.model;
import java.util.Date;
public class Student {
private int id;
private String name;
private Date birth;
private float score;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getBirth() {
return birth;
}
public void setBirth(Date birth) {
this.birth = birth;
}
public float getScore() {
return score;
}
public void setScore(float score) {
this.score = score;
}
}
与之对应的xml配置文件(Student.xml)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="Student">
<typeAlias alias="Student" type="com.lbx.model.Student" />
<select id="selectAllStudents" resultClass="Student">
select * from Student
</select>
<select id="selectStudentById" parameterClass="int" resultClass="Student">
select * from Student where id=#id#
</select>
<select id="selectStudentByName" parameterClass="String" resultClass="Student">
select * from Student where name=#name#
</select>
<insert id="insertStudent" parameterClass="Student">
insert into Student(name,birth,score) values(#name#,#birth#,#score#)
</insert>
<delete id="deleteStudentById" parameterClass="int">
delete from Student where id = #id#
</delete>
<update id="updateStudentById" parameterClass="Student">
update Student set name=#name#,birth=#birth#,score=#score# where id=#id#
</update>
</sqlMap>
dao层
package com.lbx.dao;
import java.util.List;
import com.lbx.model.Student;
public interface StudentDao {
public void addStudent(Student student);
public void deleteStudentById(int id);
public List<Student> findAllStudent();
public void updateStudent(Student student);
public List<Student> findStudentByName(String name);
public Student findStudentById(int id);
}