아주 간단 한 ibatis 예

STEP 1: author. java
package com.ibatis;
public class Author {
    private int id;
    private String name;
    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;
    }
}

STEP 2: author. xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap
PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap namespace="Author">
<!--    -->
<!--           -->
<typeAlias alias="author" type="com.ibatis.Author" />
<!--

<cacheModel type="LRU" >
        ,        ,      
 <flushInterval hours="24"></flushInterval> 
        statement ,    
 <flushOnExecute statement="updateAuthor"/>
 SIZE: cacheModel           
 <property value="1000"/>
</cacheModel>

        , :<select resultClass="author" cacheModel="authorCache">

     cacheModel"authorCache"    ,       statement      ,   
       ,           

-->
<!--Statement  -->
<select resultClass="author">

 <![CDATA[SELECT * FROM author]]>

</select>

 

<update parameterClass="author">

 <![CDATA[UPDATE author SET WHERE > 

</update>

 

<delete parameterClass="author"> 

  delete from author WHERE 

</delete> 

 

<insert parameterClass="author">

 <![CDATA[INSERT INTO author(id,name) VALUES(#id#,#name#)]]>

</insert>

</sqlMap>

세 번 째 단계: SqlMapConfig. properties
driver=com.microsoft.jdbc.sqlserver.SQLServerDriver

url=jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=ibatis

username=sa

password=sa

STEP 4: SqlMapConfig. xml
<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE sqlMapConfig

PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"

"http://www.ibatis.com/dtd/sql-map-config-2.dtd">

<!-- Ibatis    -->

<sqlMapConfig>

<!--             -->

<properties resource="com/ibatis/SqlMapConfig.properties"/>

<!--

cacheModelsEnabled:    SqlMapClient     。

enhancementEnabled:    POJO            geter/seter     ,               。

lazyLoadingEnabled:          。

maxRequests:       。

maxSessions:  Session ,          SqlMapClient 

maxTransactions:       。   

-->

<settings

cacheModelsEnabled="true"

enhancementEnabled="true"

lazyLoadingEnabled="true"

maxRequests="32"

maxSessions="10"

maxTransactions="5"

useStatementNamespaces="false"

/>

<!-- datasource -->

<transactionManager type="JDBC" >

<dataSource type="SIMPLE">

<!--JDBC  -->

<property name=JDBC.Driver value="${driver}"/>

<!--   URL-->

<property value="${url}"/>

<!--      -->

<property value="${username}"/>

<!--

좋은 웹페이지 즐겨찾기