国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
Ibatis2.0使用說(shuō)明(一)——入門實(shí)例篇
本文章將從一個(gè)Ibatis的具體示例,幫助你快速了解IBatis框架。
一個(gè)簡(jiǎn)單的IBatis應(yīng)用包含以下基本步驟:
一、 配置文件
1. 配置SqlMapConfig.properties文件
2. 配置SqlMapConfig.xml文件
3. 配置SqlMap.xml文件(可能有多個(gè)文件,一般情況下,可以一個(gè)表對(duì)應(yīng)一個(gè)SqlMap.xml文件,文件名稱可以與表名相同)
注意:上面所述的SqlMapConfig.xml文件必須在類路徑中,SqlMapConfig.properties和SqlMap.xml文件可以在類路徑中,也可以不在類路徑中。當(dāng)SqlMapConfig.properties和SqlMap.xml文件不在類路徑中的時(shí)候,配置也不同,在本文中,這三個(gè)文件都放在類路徑中。
二、 程序調(diào)用
1. 初始化SqlMapClient對(duì)象。
2. 運(yùn)行Sql語(yǔ)句:你可以調(diào)用SqlMapClient對(duì)象的queryfor...()、insert()、update()、delete()來(lái)分別執(zhí)行select、insert、update和delete操作。
好了,下面我們結(jié)合實(shí)例進(jìn)行講解:

三、實(shí)例:
下面的例子是以mysql為例進(jìn)行說(shuō)明,建立了一個(gè)author表,為了方便調(diào)試代碼,你可以將ibatis-common-2.jar、ibatis-dao-2.jar、ibatis-sqlmap-2.jar和lib目錄下的所有的jar都加載到你的程序中,在后續(xù)的文章中,將會(huì)說(shuō)明每個(gè)Jar的用途。
(一) 創(chuàng)建數(shù)據(jù)庫(kù)和表
創(chuàng)建一個(gè)名字為IBatisExample的數(shù)據(jù)庫(kù)
CREATE TABLE author (
  auth_id int(8) NOT NULL auto_increment,
  auth_name varchar(100) NOT NULL default '',
  auth_age int(3) NOT NULL default '0',
  auth_tel varchar(100) NOT NULL default '',
  auth_address varchar(100) NOT NULL default '',
  PRIMARY KEY  (auth_id)
) TYPE=MyISAM;
INSERT INTO author VALUES (1, '作者一', 30, '025-12345678', '南京');
INSERT INTO author VALUES (2, '作者二', 30, '025-12345678', '南京');
(二) 配置文件
1. 配置SqlMapConfig.properties文件
文件內(nèi)容:
driver=org.gjt.mm.mysql.Driver
url=jdbc:mysql://192.168.0.26:3306/IBatisExample?useUnicode=true&characterEncoding=GB2312
username=root
password=123456
2. 配置SqlMapConfig.xml文件
文件內(nèi)容:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
"<!-- Always ensure to use the correct XML header as above! -->
<sqlMapConfig>
<!-- The properties (name=value) in the file specified here can be used placeholders in this config
file (e.g. “${driver}”. The file is relative to the classpath and is completely optional. -->
<properties resource="SqlMapConfig.properties" />
<!-- These settings control SqlMapClient configuration details, primarily to do with transaction
management. They are all optional (more detail later in this document). -->
<settings
cacheModelsEnabled="true"
enhancementEnabled="true"
lazyLoadingEnabled="true"
maxRequests="32"
maxSessions="10"
maxTransactions="5"
useStatementNamespaces="false"
/>
<!-- Configure a datasource to use with this SQL Map using SimpleDataSource.
Notice the use of the properties from the above resource -->
<transactionManager type="JDBC" >
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="${driver}"/>
<property name="JDBC.ConnectionURL" value="${url}"/>
<property name="JDBC.Username" value="${username}"/>
<property name="JDBC.Password" value="${password}"/>
<property name="JDBC.DefaultAutoCommit" value="true" />
<property name="Pool.MaximumActiveConnections" value="10"/>
<property name="Pool.MaximumIdleConnections" value="5"/>
<property name="Pool.MaximumCheckoutTime" value="120000"/>
<property name="Pool.TimeToWait" value="500"/>
<property name="Pool.PingQuery" value="select 1 from author"/>
<property name="Pool.PingEnabled" value="false"/>
<property name="Pool.PingConnectionsOlderThan" value="1"/>
<property name="Pool.PingConnectionsNotUsedFor" value="1"/>
</dataSource>
</transactionManager>
<!-- Identify all SQL Map XML files to be loaded by this SQL map. Notice the paths
are relative to the classpath. For now, we only have one… -->
<sqlMap resource="com/ibatis/sqlmap/author.xml" />
</sqlMapConfig>
(三) 程序調(diào)用
由于源代碼很長(zhǎng),所以這里我只給出一些簡(jiǎn)單的程序調(diào)用方法,所以如果有人想要源代碼的話,可以留下你的郵箱。
1. 初始化一個(gè)SqlMapClient對(duì)象,代碼如下:
public class SqlMapConf
{
    private static SqlMapClient sqlMapClient;
    static
 {
  try
  {
      System.out.println("sqlMapClient initing.....");
   String resource = "SqlMapConfig.xml";
   Reader reader = Resources.getResourceAsReader (resource);
   sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader);
  }
  catch (Exception e)
  {
   e.printStackTrace();
   throw new RuntimeException ("Error initializing MyAppSqlConfig class. Cause: " +e);
  }
 }
    public static SqlMapClient getInstance()
    {
        return sqlMapClient;
    } 
}
2. 然后要為Author表寫一個(gè)bean,代碼如下:
public class Author
{
    private int id;
    private int age;
    private String name;  
    private String address;
    private String telephone;
   
    public int getId()
    {
        return id;
    }
    public void setId(int id)
    {
        this.id=id;
    }
    public int getAge()
    {
        return age;
    }
    public void setAge(int age)
    {
        this.age=age;
    }
    public String getName()
    {
        return name;
    }
    public void setName(String name)
    {
        this.name=name;
    }
   
    public String getAddress()
    {
        return address;
    }
    public void setAddress(String address)
    {
        this.address=address;
    }
    public String getTelephone()
    {
        return telephone;
    }
    public void setTelephone(String telephone)
    {
        this.telephone=telephone;
    }
}
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Eclipse RCP / RAP 與Spring ibatis集成
Ibatis配置詳解
ibatis調(diào)用mysql存儲(chǔ)過(guò)程示例
IBatis ORM框架的總配置文件SqlMapConfig.xml 詳細(xì)信息
BATIS 2.0 開發(fā)指南
iBatis開發(fā)環(huán)境搭建和第一個(gè)程序
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服