<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-4  評論-0  文章-0  trackbacks-0

    廢話少說。開始了。。。。。

    1.首先是JAVA類,如下:

     1package test2;
     2
     3import java.util.Date;
     4
     5public 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.一個測試類:
     1public 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 閱讀(133) 評論(0)  編輯  收藏 所屬分類: ibatis

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 久久综合AV免费观看| 成人片黄网站色大片免费观看APP| 亚洲午夜精品在线| 亚洲妇女熟BBW| 免费国产黄网站在线看| 免费成人在线电影| 日韩免费高清一级毛片在线| 亚洲精品无码永久在线观看| 亚洲综合久久综合激情久久| 亚洲一卡2卡3卡4卡国产网站 | 亚洲91av视频| 亚洲精品无码久久久久久| 美女巨胸喷奶水视频www免费| 亚洲免费在线视频观看| 亚洲国产V高清在线观看| 亚洲图片激情小说| 国产一级a毛一级a看免费人娇| 国产精品四虎在线观看免费| 五月天网站亚洲小说| 韩国免费一级成人毛片| 亚洲AV无码1区2区久久| 亚洲一区免费在线观看| 亚洲精品亚洲人成在线| 国产精品亚洲αv天堂无码| 亚洲精品蜜夜内射| 国产片AV片永久免费观看| 亚洲午夜精品久久久久久浪潮| 十八禁在线观看视频播放免费| 亚洲激情在线观看| 中文字幕av无码不卡免费| 亚洲乱亚洲乱淫久久| 嫩草影院免费观看| 亚洲一区电影在线观看| 免费国产成人午夜私人影视| 亚洲精品宾馆在线精品酒店| 亚洲色图综合在线| 韩国免费一级成人毛片| 中文字幕在线免费看| 亚洲乱码一二三四区乱码| 午夜国产精品免费观看| 一个人看的www免费高清|