ibatis项目应用
创建数据库表:
create table u_student(
student_id number 16,
student_name varchar2(108),
student_code number 32,
create_date date,
update_date date,
constraint pk_student_id primary key (student_id)
);
创建索引序列:
create sequence u_student_sequence minvalue 1 maxvalue 99999999999999999 start with 11 increment 1 cache 20;
实体类:
import com
public class Student{ private int student_id;
}
student.ibatis.xml文件
<sqlMap namespace="Student">
<typeAlias alias="Student" type="com.Student" />
<resultMap id="StudentMap" class="Student"><result property="studentId" column=""></result></resultMap>
<select id="findCountStudentId" parameterClass="Student" resultClass="java.lang.Integer">
select count(c.student_id)from student c
<dynamic prepend="WHERE">
<isNotEmpty prepend=" AND " property="studentName" ><![CDATA[c.STUDENT_ID=#studentName#]]</isNotEmpty>
</dynamic>
</select>
</sqlMap>
import com.dao
导包略.....
public class StudentDao extends BaseDao{
public int countStudentId(Student s){
return (Integer)this.getSqlMapClientTemplate("findCountStudentId",s);
}
}
public class Test{
StudentDao s = new StudentDao();
public static void main(Stirng[] args){
Student s = new Student();
s.countStudentId();
}
}
这里只是各个点中完整的写法。可能还有其它东西需要些的,后续完善。。。