iBATIS 3 for Java 무작정 해보기..

  제이쿼리 2009. 12. 1 오전 11:03:20 2010. 02. 18 (0)

2009년 8월에 iBATIS 3 for Java (BETA) 가 공개 되었더군요...
현재는 beta 3 이군여..
iBATIS 3 for Java User Guide 문서를 바탕으로 해보기..
SqlMapClient 에서 제공한던것이 .
org.apache.ibatis.session.SqlSession 가 그역활를 하는듯
기존 sqlmap......xml 이던것이 mapper라는 이름으로 바뀌었군여..

그외 JAVA 5 의 기능인 annotation으로 .....xml 파일을 대체할수 있다는 것도...
전체적으로 iBatis3은 기존버전에서 많은 변화를 꾀한듯 합니다.....hibernate와 많이 비슷해져가고 있다는 느낌도 듭니다......

정말....기술은 ..계속 진보 하는군요...
전체적으로 개발이 더 쉬워 진듯 합니다..

Configuration.xml (설정파일)
 
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//ibatis.apache.org//DTD Config 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-config.dtd">
<configuration>
    <properties resource="conf.properties"/>
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC" />
            <dataSource type="POOLED">
                <property name="driver" value="${driver}" />
                <property name="url" value="${url}" />
                <property name="username" value="${username}" />
                <property name="password" value="${password}" />
            </dataSource>
        </environment>
    </environments>
     
    <mappers>
        <mapper resource="BlogMapper.xml" />
    </mappers>
     
</configuration>

Ibatis3Test.java Main 클래스

package jylee.main;

import java.io.IOException;
import java.io.Reader;

import jylee.dto.Blog;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class Ibatis3Test {

    /**
     * @param args
     */
    public static void main(String[] args) {
     
        try {
           
            Reader  reader = Resources.getResourceAsReader("Configuration.xml");
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
            SqlSession session = sqlSessionFactory .openSession();

            try {
                Blog blog = (Blog) session.selectOne("ibatis3.mapper.BlogMapper.selectBlog", 101);
                if(blog==null){
                    System.out.println("dd");
                }else{
                    System.out.println("id=="+blog.getId());
                }
                blog = new Blog();
                blog.setId(100);
                session.insert("ibatis3.mapper.BlogMapper.insertBlog", blog);//자료 추가
                blog = (Blog) session.selectOne("ibatis3.mapper.BlogMapper.selectBlog", 100);//추가한 자료가져오기..
                if(blog==null){
                    System.out.println("dd");
                }else{
                    System.out.println("id=="+blog.getId());
                }
                List<Blog> blogList = (List<Blog>) session.selectList("ibatis3.mapper.BlogMapper.selectBlogList");//전체자료조회
                for (Blog blog2 : blogList) {
                    System.out.println("id=="+blog2.getId());
                }
            } finally {
                session.close();
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}


테스트용 테이블 생성
CREATE TABLE BLOG
( ID int,
primary key (id)
);
테스트 자료
insert into blog values(101);

Blog.java(모델클래스)

package jylee.dto;
public class Blog {
    private int id;
    public int getId() {
        return id;
    }
   public void setId(int id) {
        this.id = id;
    }
}

BlogMapper.xml mapper 파일

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
<mapper namespace="ibatis3.mapper.BlogMapper">
    <select id="selectBlog" parameterType="int" resultType="jylee.dto.Blog">
        select * from Blog where id = #{id}
    </select>
    <select id="selectBlogList"  resultType="jylee.dto.Blog">
        select * from Blog
    </select>
    <insert id="insertBlog" parameterType="jylee.dto.Blog">
        insert into blog values(#{id})
    </insert>
</mapper>

실행결과
----------------------------------------------
id==101
id==100
id==100
id==101

참조
http://ibatis.apache.org/index.html
http://ibatis.apache.org/java.cgi
http://opensource.atlassian.com/confluence/oss/display/IBATIS/iBATIS+3.0+Whiteboard+-+Korean
http://opensource.atlassian.com/confluence/oss/display/IBATIS/iBATIS+3.0+Whiteboard
Tags:
삭제 수정 댓글
2010. 7. 27 오전 12:14:22 (59.42.117.***)

GLT10a07river27    
<a href="http://www.replica-hermes.com"><b>hermes handbags</b></a>
<a href="http://www.replica-hermes.com"><b>Hermes Bag</b></a>
<A href="http://www.omega-watches-replica.com"><b>Omega Watches</b></a>
<A href="http://www.omega-watches-replica.com"><b>Replica Omega</b></a>
<A href="http://www.omega-watches-replica.com"><b>Omega Replica Watches</b></a>
<a href="http://www.replica-hermes.com"><b>replica hermes</b></a>
<a href="http://www.replica-hermes.com"><b>Hermes Birkin</b></a>
<a href="http://www.replica-hermes.com"><b>Replica Hermes Birkin</b></a>
<a href="http://www.replica-hermes.com"><b>cheap hermes handbags</b></a>
<A href="http://www.replica-cartier-watches.com"><b>Cartier Watches</b></a>
<A href="http://www.replica-cartier-watches.com"><b>Replica Cartier Watches</b></a>
<a href="http://www.handbagsspace.com"><b>Louis Vuitton handbags</b></a>
<a href="http://www.handbagsspace.com"><b>Gucci handbags</b></a>
<a href="http://www.handbagsspace.com"><b>Prada handbags</b></a>
<a href="http://www.handbagsspace.com"><b>Louis Vuitton Wallets</b></a>
<a href="http://www.handbagsspace.com"><b>Gucci Wallets</b></a>
<a href="http://www.handbagsspace.com"><b>Prada Wallets</b></a>
<a href="http://www.honeyreplicas.com"><b>Replica Handbags</b></a>
<a href="http://www.exact-handbags.com"><b>Hermes Handbags</b></a>

<a href="http://www.replicahandbagsbox.com"><b>replica handbags</b></a>
<a href="http://www.replicahandbagsbox.com"><b>louis vuitton replica handbags</b></a>
<a href="http://www.replicahandbagsbox.com/Replica-Handbags/BURBERRY-Burberry-Handbag-161-1.htm"><b>Burberry Handbags</b></a>
<a href="http://www.replicahandbagsbox.com/Replica-Handbags/PRADA-Prada-Handbags-65-1.htm"><b>Prada Handbags</b></a>

<a href="http://www.replicawatchesbox.com"><b>Replica Watches</b></a>
<a href="http://www.replicawatchesbox.com"><b>Omega replica Watches</b></a>

<a href="http://www.honeyreplicas.com/HandBags_LouisVuitton_5.html">Replica Louis Vuitton</a>
<a href="http://www.honeyreplicas.com/HandBags_Gucci_6.html">Replica Gucci</a>

<A href="http://www.omega-watches-replica.com"><b>Omega Watch for men</b></a>
<A href="http://www.omega-watches-replica.com"><b>Omega Watch for women</b></a>
<A href="http://www.omega-watches-replica.com/Omega-Classic-Watches_1.html"><b>Omega Classic Watches</b></a>
<A href="http://www.omega-watches-replica.com/Omega-CO-AXIAL-Watches_2.html"><b>Omega CO AXIAL Watches</b></a>
<A href="http://www.omega-watches-replica.com/Omega-CONSTELLATION-Watches_3.html"><b>Omega CONSTELLATION Watches</b></a>
<A href="http://www.omega-watches-replica.com/Omega-DEVILLE-Watches_4.html"><b>Omega DEVILLE Watches</b></a>
<A href="http://www.omega-watches-replica.com/Omega-Museum-Watches_5.html"><b>Omega Museum Watches</b></a>
<A href="http://www.omega-watches-replica.com/Omega-OLYMPIC-COLLECTION-Watches_6.html"><b>Omega OLYMPIC COLLECTION Watches</b></a>
<A href="http://www.omega-watches-replica.com/Omega-Railmaster-Watches_8.html"><b>Omega Railmaster Watches</b></a>
<A href="http://www.omega-watches-replica.com/Omega-Seamaster-Watches_9.html"><b>Omega Seamaster Watches</b></a>
<A href="http://www.omega-watches-replica.com/Omega-SPEEDMASTER-Watches_10.html"><b>Omega SPEEDMASTER Watches</b></a>

<a href="http://www.handbagsoem.com"><b>adidas shoes, air jordans</b></a>
<a href="http://www.oemhandbags.com/"><b>Designer Handbags,Replica Bags Blogs</b></a>
<a href="http://www.oempurses.com/"><b>Replica Bags,Replica Omega Watches Blogs</b></a>
<a href="http://www.oempurse.com"><b>air jordans, jordan fusions</b></a>
<a href="http://www.sunglassesoem.com"><b>jordan fusions,Chanel Shoes</b></a>
<a href="http://www.ledlightoem.com/"><b>Omega Watches,Replica Watches Blogger</b></a>
<a href="http://www.ledlights-oem.com"><b>Replica Fashion Handbags Blogs</b></a>
<a href="http://www.ledlightoem.com"><b>Christian Louboutin Shoes, Manolo Blahnik Shoes</b></a>
<a href="http://www.makehermes.com"><b>Manolo Blahnik Shoes, Shoe Trends</b></a>
<a href="http://www.hermesmaker.com"><b>This week in shoes, spring 21 shoes</b></a>

삭제 수정 댓글
2010. 8. 26 오후 3:40:46 (220.177.81.***)
삭제 수정 댓글
2010. 8. 26 오후 3:40:47 (220.177.81.***)
삭제 수정 댓글
2010. 8. 26 오후 3:40:47 (220.177.81.***)
삭제 수정 댓글
2010. 8. 26 오후 3:40:47 (220.177.81.***)
삭제 수정 댓글
2010. 8. 26 오후 3:40:47 (220.177.81.***)

비밀번호를 입력하여 주세요


제목 iBATIS 3 for Java 무작정 해보기..
내용
발송할 주소
선택 나의 트위터 친구 트위터
계정정보 아이디: / 패스워드 : / 친구 아이디:
내용 0