打印本文 打印本文 关闭窗口 关闭窗口
iBATIS SQL Maps(四)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数3371  更新时间:2007/11/14 12:58:25  文章录入:mintao  责任编辑:mintao
people);
       sqlMap.insert("insertAutoInfo",autoInfo);
     
       sqlMap.commitTransaction();
  }finally{
       sqlMap.endTransaction();
  }
 }
}

 

程序代码也是简单组合一下而已,想想 Hibernate 又是怎么写的呢?相信有 JDBC 经验的程序员应该更喜欢 iBATIS SQL Maps

 

斗转星移、峰回路转,张三在经历过生意红火之后,接下来的一年内生意场上连连告负,不得不把自己的摊子收缩一下。这第一件事要把跑运输的车卖掉,就是那辆牌照为A00002”

 

相应映射文件只需小小修改:

 

<?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>
 
  <delete id="deleteAutoInfo" parameterClass="bo.AutoInfo">
    <![CDATA[
    delete from auto_info where license_plate=#licensePlate# and owner_no=#ownerNo.id#
    ]]>
  </delete>

    <resultMap id="get-autoInfo-result" class="bo.AutoInfo">
        <result property="id" column="auto_id"/>
        <result property="licensePlate" column="license_plate"/>
    </resultMap>

    <resultMap id="get-people-result" class="bo.People">
        <result property="id" column="owner_id"/>
        <result property="name" column="name"/>
        <result property="address" column="address"/>
        <result property="autoInfoList" column="owner_id" select="getAutoInfo"/>
    </resultMap>

  <select id="getPeople" resultMap="get-people-result" parameterClass="bo.People">
       <![CDATA[
       select * from people
       ]]>
       <dynamic prepend="where">
         <isNotNull property="id">
           <![CDATA[
           owner_id=#id#
           ]]>
         </isNotNull>
       </dynamic>
  </select>

  <select id="getAutoInfo" resultMap="get-autoInfo-result" parameterClass="int">
       <![CDATA[
       select * from auto_info where owner_no=#id#
        ]]>
  </select>
 
</sqlMap>

 

添加了一个 delete 类型的 Mapped Statement。同样,也无需再解释了。相应程序代码:

 

package test;

import java.io.Reader;

import com.ibatis.sqlmap.client.*;
import com.ibatis.common.resources.*;

import bo.*;

public class AutoMag {

 private Reader reader;
 private SqlMapClient sqlMap;
 private String resource = "SqlMapConfig.xml";
 
 public void delPeople() throws Exception{
  try{
     

上一页  [1] [2] [3]  下一页

打印本文 打印本文 关闭窗口 关闭窗口