ibatis配置方法

本文深入探讨了SQLMap配置文件的使用,包括总配置文件sqlmap-config.xml的详细解析,以及具体SQL语句文件的生成流程。文章还介绍了如何通过自动生成工具简化SQL语句的创建,并提供了实例代码来展示其特性。
摘要由CSDN通过智能技术生成

sqlmap配置

总配置文件sqlmap-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<settings cacheModelsEnabled="false" enhancementEnabled="false"
lazyLoadingEnabled="false" maxRequests="3000" maxSessions="3000"
maxTransactions="3000" useStatementNamespaces="false" />
<sqlMap resource="com/taobao/cun/scc/biz/sqlmap/base/sqlmap_common.xml"/>
<sqlMap resource="com/taobao/cun/scc/biz/sqlmap/base/sqlmap_base_cuntao_logistics_order.xml"/>
</sqlMapConfig>:

其中,
cacheModelsEnabled:对在此配置文件下的所有cache 进行全局性开/关设置。
enhancementEnabled:全局性地启用或禁用运行时字节码增强,以优化访 问 Java Bean 属性的性能,同时优化延迟加载的性能。
lazyLoadingEnabled:全局性设置懒加载。如果设为‘false’,则所有相关联的都会被初始化加载。
maxRequests,maxSessions,maxTransactions:同时执行 SQL 语句的最大线程数,同一时间内活动的最大session数,同时进入 SqlMapClient.startTransaction()的最大线程 数。通常三者关系为<<<。
useStatementNamespaces:必须使用全限定名来引用 mapped statement。
<sqlMap 标签下为sql语句的文件。

具体的sqlmap文件

sql语句用辰辉的自动生成工具,优点:
0.全自动生成(Do,Dao,DaoImp,Sqlmap文件),可以轻松应对表结构变化。将通用的字段提取成基类(id,creator,GMTcreate..),
1.Do层中,每个属性均有change布尔值来保证只更新用过set方法的参数。
2.将通用操作(select所有,动态参数,orderby,limit)提取成common,通过include标签嵌入sql语句,代码会非常简洁。
limit用来分页的防止注入写法:$pageOrderList[].orderColumn:METADATA$ $pageOrderList[].orderDir:SQLKEYWORD$
3.所有操作都<![CDATA[ ]]> 保证可以使用><等特殊字符。

例子
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
<sqlMap namespace="CuntaoLogisticsOrder">

<typeAlias alias="CuntaoLogisticsOrder" type="com.taobao.cun.scc.biz.logisticsorder.dataobject.CuntaoLogisticsOrderDO"/>

<sql id="CuntaoLogisticsOrder.COMMON_SELECT">
<![CDATA[
SELECT 
id as id
, gmt_create as gmtCreate
, creator as creator
, gmt_modified as gmtModified
, modifier as modifier
, is_deleted as isDeleted
, purchase_order_id as purchaseOrderId
, consignee_name as consigneeName
, consignee_address as consigneeAddress
, consignee_post as consigneePost
, consignee_phone as consigneePhone
, consignee_mobile_phone as consigneeMobilePhone
, consignee_province as consigneeProvince
, consignee_city as consigneeCity
, consignee_county as consigneeCounty
, consignee_town as consigneeTown
, memo as memo
, version as version
, out_logistics_id as outLogisticsId
, logistics_status as logisticsStatus
, consign_time as consignTime
from cuntao_logistics_order where is_deleted = 'n'
]]>
</sql>

<sql id="CuntaoLogisticsOrder.COMMON_CONDITION">
<isNotNull property="id" prepend="and">
id=#id#
</isNotNull>
<isNotNull property="gmtCreate" prepend="and">
gmt_create=#gmtCreate#
</isNotNull>
<isNotNull property="creator" prepend="and">
creator=#creator#
</isNotNull>
<isNotNull property="gmtModified" prepend="and">
gmt_modified=#gmtModified#
</isNotNull>
<isNotNull property="modifier" prepend="and">
modifier=#modifier#
</isNotNull>
<isNotNull property="isDeleted" prepend="and">
is_deleted=#isDeleted#
</isNotNull>
<isNotNull property="purchaseOrderId" prepend="and">
purchase_order_id=#purchaseOrderId#
</isNotNull>
<isNotNull property="consigneeName" prepend="and">
consignee_name=#consigneeName#
</isNotNull>
<isNotNull property="consigneeAddress" prepend="and">
consignee_address=#consigneeAddress#
</isNotNull>
<isNotNull property="consigneePost" prepend="and">
consignee_post=#consigneePost#
</isNotNull>
<isNotNull property="consigneePhone" prepend="and">
consignee_phone=#consigneePhone#
</isNotNull>
<isNotNull property="consigneeMobilePhone" prepend="and">
consignee_mobile_phone=#consigneeMobilePhone#
</isNotNull>
<isNotNull property="consigneeProvince" prepend="and">
consignee_province=#consigneeProvince#
</isNotNull>
<isNotNull property="consigneeCity" prepend="and">
consignee_city=#consigneeCity#
</isNotNull>
<isNotNull property="consigneeCounty" prepend="and">
consignee_county=#consigneeCounty#
</isNotNull>
<isNotNull property="consigneeTown" prepend="and">
consignee_town=#consigneeTown#
</isNotNull>
<isNotNull property="memo" prepend="and">
memo=#memo#
</isNotNull>
<isNotNull property="version" prepend="and">
version=#version#
</isNotNull>
<isNotNull property="outLogisticsId" prepend="and">
out_logistics_id=#outLogisticsId#
</isNotNull>
<isNotNull property="logisticsStatus" prepend="and">
logistics_status=#logisticsStatus#
</isNotNull>
<isNotNull property="consignTime" prepend="and">
consign_time=#consignTime#
</isNotNull>
</sql>
<sql id="CUNTAO_PAGING_COMMON">
<dynamic>
<isNotNull property="pageSize">
<![CDATA[
limit #pageStart# , #pageSize#
]]>
</isNotNull>
</dynamic>
</sql>
<sql id="CUNTAO_ORDER">
<dynamic>
<isNotNull property="pageOrderList" prepend="ORDER BY ">
<iterate property="pageOrderList" conjunction=",">
<![CDATA[ 
$pageOrderList[].orderColumn:METADATA$ $pageOrderList[].orderDir:SQLKEYWORD$ 
]]>
</iterate>
</isNotNull>
</dynamic>
</sql>

<select id="CuntaoLogisticsOrder.SELECT" resultClass="CuntaoLogisticsOrder" parameterClass="com.taobao.cun.scc.biz.logisticsorder.dataobject.CuntaoLogisticsOrderDO" >
<include refid="CuntaoLogisticsOrder.COMMON_SELECT"/>
<include refid="CuntaoLogisticsOrder.COMMON_CONDITION"/>
<include refid="CUNTAO_ORDER"/>
<include refid="CUNTAO_PAGING_COMMON"/>
</select>

</sqlMap>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值