ibatis
学习笔记
1
?/p>
搭建环境?/p>
?/p>
1
?/p>
、创?/p>
ibatis_test
项目?/p>
?/p>
2
?/p>
、添?/p>
SQL2000
驱动?/p>
msbase.jar
?/p>
mssqlserver.jar
?/p>
msutil.jar
?/p>
ibatis-2.3.3.720.jar
包?/p>
2
、配置文件:
?/p>
1
?/p>
?/p>
JDBC
连接属性文件:?/p>
src
目录下添?/p>
SqlMap.properties
属性文件,主要包括
JDBC
?
接的主要信息?/p>
driver=
?/p>
url=
?/p>
username=
?/p>
password=,
也可以见
JDBC
连接?/p>
信息直接写到总配置文件中?/p>
?/p>
2
?/p>
、配置每个实体的映射文件?/p>
map
文件?/p>
?/p>
?/p>
Student.xml
文件,其主要是包括对实体进行
CURD
操作?/p>
SQL
语句的映射?/p>
?/p>
3
?/p>
、添加总配置文件:
(参?/p>
SqlMapConfig.xml
文件?/p>
其主要功能是导入
SqlMap.properties
?/p>
Student.xml
文件,进行统一管理
3
、创建相应的类:
?/p>
1
?/p>
、建立实体类
Student.java
类?/p>
?/p>
2
?/p>
、建立管理类接口
StudentDao
,和实现?/p>
StudentDaoImpl
4
、测?/p>
CRUD
操作?/p>
?/p>
1
)、在
StudentDaoImpl
类中添加读取配置
?/p>
2
?/p>
、测试查询所有信息的方法
queryAllStudent
(),在
Student.xml
文件中配?/p>
SQL
语句映射信息。例如:
<
?/p>
--
查找所有用?/p>
-->
<
select
id
=
"selectAllStudents"
resultClass
=
"Student"
>
select * from t_student;
</
select
>
?/p>
queryAllStudent
()方法中使?/p>
sqlMapClient
?/p>
queryForList
()方法进行调用?/p>
public
List<Student> queryAllStudent() {
List<Student> studntList =
null
;
try
{
studntList=
sqlMapClient
.queryForList(
"selectAllStudents"
);
}
catch
(SQLException e) {