步入JAVA殿堂
小心走路,抬頭做人。
BlogJava
首頁
新隨筆
聯(lián)系
聚合
管理
隨筆-4 評論-0 文章-0 trackbacks-0
初次接觸iBatis
廢話少說。開始了。。。。。
1.首先是JAVA類,如下:
1
package
test2;
2
3
import
java.util.Date;
4
5
public
class
User
{
6
7
private
Long id;
8
9
private
String userName;
10
11
private
int
userAge;
12
13
private
Date brithday;
14
15
//
getter and setter
16
}
17
2.和hibernate一樣映射文件:
1
<?
xml version="1.0" encoding="UTF-8"
?>
2
3
<!
DOCTYPE sqlMap
4
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
5
"http://ibatis.apache.org/dtd/sql-map-2.dtd"
>
6
<
sqlMap
namespace
="User"
>
7
<
typeAlias
alias
="User"
type
="test2.User"
/>
8
<
resultMap
class
="User"
id
="AccountResult"
>
9
<
result
property
="id"
column
="ID"
/>
10
<
result
property
="userName"
column
="USER_NAME"
/>
11
<
result
property
="userAge"
column
="USER_AGE"
/>
12
<
result
property
="brithday"
column
="USER_BRITHDAY"
/>
13
</
resultMap
>
14
<
select
id
="selectAllUsers"
resultMap
="AccountResult"
>
15
select * from USERS
16
</
select
>
17
<
insert
id
="insertAccount"
parameterClass
="User"
>
18
insert into USERS (
19
ID,
20
USER_NAME,
21
USER_AGE,
22
USER_BRITHDAY )
23
values (
24
#id#,#userName#, #userAge#, #brithday#
25
)
26
</
insert
>
27
</
sqlMap
>
3.一個測試類:
1
public
class
Client
{
2
3
private
static
SqlMapClient sqlMapper;
4
5
static
{
6
try
{
7
Reader reader
=
Resources.getResourceAsReader(
"
test/SqlMapConfig.xml
"
);
8
sqlMapper
=
SqlMapClientBuilder.buildSqlMapClient(reader);
9
reader.close();
10
}
catch
(IOException e)
{
11
//
Fail fast.
12
throw
new
RuntimeException(
"
Something bad happened while building the SqlMapClient instance.
"
+
e, e);
13
}
14
}
15
16
public
static
List
<
User
>
selectAllAccounts ()
throws
SQLException
{
17
return
sqlMapper.queryForList(
"
selectAllUsers
"
);
18
}
19
20
public
static
void
insert(User user)
throws
SQLException
{
21
sqlMapper.insert(
"
insertAccount
"
, user);
22
}
23
public
static
void
main(String[] args)
{
24
User user
=
new
User();
25
user.setUserName(
"
Gordon
"
);
26
user.setUserAge(
24
);
27
user.setBrithday(
new
Date());
28
try
{
29
Client.insert(user);
30
}
catch
(SQLException e1)
{
31
//
TODO Auto-generated catch block
32
e1.printStackTrace();
33
}
34
List
<
User
>
list
=
null
;
35
try
{
36
list
=
Client.selectAllAccounts();
37
for
(Iterator
<
User
>
i
=
list.iterator();i.hasNext();)
{
38
System.out.println(i.next().getUserName());
39
}
40
}
catch
(SQLException e)
{
41
e.printStackTrace();
42
}
43
44
}
45
}
第一個例子完成,還有ibatis.jar mysql.jar
posted on 2008-09-24 23:44
Gordon
閱讀(129)
評論(0)
編輯
收藏
所屬分類:
ibatis
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發(fā)表評論。
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
<
2008年9月
>
日
一
二
三
四
五
六
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
常用鏈接
我的隨筆
我的評論
我的參與
留言簿
(1)
給我留言
查看公開留言
查看私人留言
隨筆分類
(4)
Ajax(1)
Flex
ibatis(1)
Java(2)
spring
struts2
隨筆檔案
(4)
2008年9月 (3)
2008年8月 (1)
搜索
最新評論
閱讀排行榜
1.?Ajax實(shí)現(xiàn)google的自動完成(331)
2.?初步認(rèn)識JUnit(144)
3.?JAVA中的四種排序(135)
4.?初次接觸iBatis(129)
評論排行榜
1.?初次接觸iBatis(0)
2.?JAVA中的四種排序(0)
3.?初步認(rèn)識JUnit(0)
4.?Ajax實(shí)現(xiàn)google的自動完成(0)
Powered by:
博客園
模板提供:
滬江博客
Copyright ©2025 Gordon
主站蜘蛛池模板:
国产精品自在自线免费观看
|
亚洲黄色免费网站
|
黄页网站在线观看免费高清
|
成人一区二区免费视频
|
久久久亚洲精华液精华液精华液
|
美女被免费视频网站a
|
亚洲免费一级视频
|
久久精品国产精品亚洲蜜月
|
亚洲精品无码永久在线观看
|
国产禁女女网站免费看
|
www.999精品视频观看免费
|
久久久久国产免费
|
三年片免费高清版
|
日本成年免费网站
|
久久综合国产乱子伦精品免费
|
国产VA免费精品高清在线
|
国产偷国产偷亚洲高清在线
|
亚洲色无码专区一区
|
亚洲国产成人精品无码区在线秒播
|
亚洲国产精品高清久久久
|
在线亚洲97se亚洲综合在线
|
亚洲AⅤ优女AV综合久久久
|
亚洲精品视频免费看
|
亚洲成a人片在线观看无码专区
|
中文字幕专区在线亚洲
|
亚洲av再在线观看
|
亚洲另类激情专区小说图片
|
亚洲AV无码乱码在线观看性色扶
|
亚洲国产日韩在线一区
|
亚洲视频中文字幕在线
|
久久狠狠高潮亚洲精品
|
亚洲黄色网址大全
|
亚洲欧洲日本精品
|
91亚洲国产成人久久精品网址
|
国产免费久久精品99re丫y
|
在线精品一卡乱码免费
|
亚洲一区二区三区免费在线观看
|
日本最新免费网站
|
97无码免费人妻超级碰碰夜夜
|
免费看少妇作爱视频
|
国产免费69成人精品视频
|