ibatis tips

一、One to Many配置
<typeAlias alias="customer" type="bean.Customer"/>
<typeAlias alias="order" type="bean.Order"/>
<resultMap id="orderMap" class="order">
<result property="id" column="id"/>
<result property="orderNumber" column="order_number"/>
</resultMap>
<resultMap id="customerMap" class="customer" groupBy="id">
<result property="id" column="id"></result>
<result property="name" column="name"></result>
<result property="phone" column="phone"></result>
<result property="married" column="married" javaType="java.lang.Boolean" jdbcType="Date"></result>
<result property="sex" column="sex"></result>
<result property="registeredTime" column="registered_time"></result>
<result property="homeAddress" column="home_address" ></result>
<result property="orderList" resultMap="orderMap" ></result>
</resultMap>
<select id="getCustomer" parameterClass="java.lang.Integer" resultMap="customerMap">
<![CDATA[
   select a.id,a.name,a.phone,a.married,a.sex,a.registered_time ,b.home_address,c.id,c.order_number
   from t_customer a, t_address b ,t_order c
   where a.id = #value:NUMERIC#
	AND a.address_id = b.id
	AND a.id=c.customer_id
]]>
</select>

二、批量更新或插入数据
为提高性能,最好在更新和插入之前加上
getSqlMapClient().startTransaction();
getSqlMapClient().startBatch();
结束后加上
getSqlMapClient().executeBatch();
getSqlMapClient().commitTransaction();
三、参数传递时的注意点
当参数传递为一个List时,如Id list,然后在ibatis中select出这些有这些ID的数据的时,会存在一个问题:当ID List项大于1000时会报错,因此需要在传入之前做好截取操作,每次传入1000个记录。这是jdbc中做的限制,然而,oracle中没有作这种限制。

猜你喜欢

转载自ch19880311.iteye.com/blog/1022134