yxhxj2006

          常用鏈接

          統計

          最新評論

          iBatis中使用動態查詢

          iBatis中的動態查詢還是比較好用的 
          如果想深入學習,可以參考 Manning.iBATIS.in.Action.Jan.2007 
          下面給出幾個例子和dtd定義: 
          <select id="selectDispatchedKey" parameterClass="KeyAndKeyFlowInfo" resultMap="KeyAndKeyFlowResult"> 
          select distinct 
          KEY_ID, 
          USER_ID, 
          INITIATOR, 
          INIT_DATE, 
          INITIATOR_EMAIL, 
          SGS_KEY.BRANCH_NAME, 
          APPROVER, 
          APPROVER_EMAIL, 
          APPROVE_DATE 
          from 
          SGS_KEY, 
          SGS_KEY_FLOW 
          where SGS_KEY.APPLY_FLOW_ID=SGS_KEY_FLOW.KEY_FLOW_ID 
          <dynamic prepend="and" open="(" close=")"> 
          <isNotNull property="ki.userId" prepend="and" removeFirstPrepend="false"> 
          USER_ID = #ki.userId# 
          </isNotNull> 
          <isNotNull property="kfi.initiator" prepend="and"> 
          INITIATOR = #kfi.initiator# 
          </isNotNull> 
          <isNotNull property="kfi.initDate" prepend="and"> 
          INIT_DATE = #kfi.initDate# 
          </isNotNull> 
          </dynamic> 
          </select> 

          <update id="updateKeyFlow" parameterClass="KeyFlowInfo"> 
          update SGS_KEY_FLOW set 
          <dynamic> 
          KEY_FLOW_ID =#keyFlowId# 
          <isNotNull property="branchName" prepend=","> 
          BRANCH_NAME = #branchName# 
          </isNotNull> 
          <isNotEqual property="operation" prepend="," compareProperty="operation" compareValue="0"> 
          OPERATION = #operation# 
          </isNotEqual> 
          <isNotNull property="initiator" prepend=","> 
          INITIATOR = #initiator# 
          </isNotNull> 
          <isNotNull property="initiatorEmail" prepend=","> 
          INITIATOR_EMAIL = #initiatorEmail# 
          </isNotNull> 
          <isNotNull property="initDate" prepend=","> 
          INIT_DATE = #initDate# 
          </isNotNull> 
          <isNotNull property="approver" prepend=","> 
          APPROVER = #approver# 
          </isNotNull> 
          <isNotNull property="approverEmail" prepend=","> 
          APPROVER_EMAIL = #approverEmail# 
          </isNotNull> 
          <isNotNull property="approveDate" prepend=","> 
          APPROVE_DATE = #approveDate# 
          </isNotNull> 
          <isNotEqual property="keyNum" prepend="," compareProperty="keyNum" compareValue="0"> 
          KEY_NUM = #keyNum# 
          </isNotEqual> 
          <isNotNull property="applyReason" prepend=","> 
          APPLY_REASON = #applyReason# 
          </isNotNull> 
          <isNotNull property="rejectReason" prepend=","> 
          REJECT_REASON = #rejectReason# 
          </isNotNull> 
          </dynamic> 
          where 
          KEY_FLOW_ID =#keyFlowId# 
          </update> 
          0:26 2008-2-20補充: 

          讓iBatis中的insert返回主鍵 [ibatis insert 返回 自增主鍵] 
          iBatis SQL-map 文件書寫注意事項 


          http://ibatis.apache.org/dtd/sql-map-2.dtd 中有<dynamic>的定義 
          <!-- - - - - - - - - - - - - - - - - - - - - - - - - <br> DYNAMIC ELEMENTS <br>- - - - - - - - - - - - - - - - - - - - - - - - --> 
          <!ELEMENT dynamic (#PCDATA | include | iterate | isParameterPresent | isNotParameterPresent | isEmpty | isNotEmpty | isNotNull | isNull | isNotEqual | isEqual | isGreaterThan | isGreaterEqual | isLessThan | isLessEqual | isPropertyAvailable | isNotPropertyAvailable)*> 
          <!ATTLIST dynamic >
          prepend CDATA #IMPLIED 
          open CDATA #IMPLIED 
          close CDATA #IMPLIED 

          <!ELEMENT isNotNull (#PCDATA | include | iterate | isParameterPresent | isNotParameterPresent | isEmpty | isNotEmpty | isNotNull | isNull | isNotEqual | isEqual | isGreaterThan | isGreaterEqual | isLessThan | isLessEqual | isPropertyAvailable | isNotPropertyAvailable)*> 
          <!ATTLIST isNotNull >
          prepend CDATA #IMPLIED 
          open CDATA #IMPLIED 
          close CDATA #IMPLIED 
          property CDATA #IMPLIED 
          removeFirstPrepend (true|false) #IMPLIED 

          <!ELEMENT isNull (#PCDATA | include | iterate | isParameterPresent | isNotParameterPresent | isEmpty | isNotEmpty | isNotNull | isNull | isNotEqual | isEqual | isGreaterThan | isGreaterEqual | isLessThan | isLessEqual | isPropertyAvailable | isNotPropertyAvailable)*> 
          <!ATTLIST isNull >
          prepend CDATA #IMPLIED 
          open CDATA #IMPLIED 
          close CDATA #IMPLIED 
          property CDATA #IMPLIED 
          removeFirstPrepend (true|false) #IMPLIED 

          <!ELEMENT isNotPropertyAvailable (#PCDATA | include | iterate | isParameterPresent | isNotParameterPresent | isEmpty | isNotEmpty | isNotNull | isNull | isNotEqual | isEqual | isGreaterThan | isGreaterEqual | isLessThan | isLessEqual | isPropertyAvailable | isNotPropertyAvailable)*> 
          <!ATTLIST isNotPropertyAvailable >
          prepend CDATA #IMPLIED 
          open CDATA #IMPLIED 
          close CDATA #IMPLIED 
          property CDATA #REQUIRED 
          removeFirstPrepend (true|false) #IMPLIED 

          <!ELEMENT isPropertyAvailable (#PCDATA | include | iterate | isParameterPresent | isNotParameterPresent | isEmpty | isNotEmpty | isNotNull | isNull | isNotEqual | isEqual | isGreaterThan | isGreaterEqual | isLessThan | isLessEqual | isPropertyAvailable | isNotPropertyAvailable)*> 
          <!ATTLIST isPropertyAvailable >
          prepend CDATA #IMPLIED 
          open CDATA #IMPLIED 
          close CDATA #IMPLIED 
          property CDATA #REQUIRED 
          removeFirstPrepend (true|false) #IMPLIED 

          <!ELEMENT isEqual (#PCDATA | include | iterate | isParameterPresent | isNotParameterPresent | isEmpty | isNotEmpty | isNotNull | isNull | isNotEqual | isEqual | isGreaterThan | isGreaterEqual | isLessThan | isLessEqual | isPropertyAvailable | isNotPropertyAvailable)*> 
          <!ATTLIST isEqual >
          prepend CDATA #IMPLIED 
          open CDATA #IMPLIED 
          close CDATA #IMPLIED 
          property CDATA #IMPLIED 
          removeFirstPrepend (true|false) #IMPLIED 
          compareProperty CDATA #IMPLIED 
          compareValue CDATA #IMPLIED 

          <!ELEMENT isNotEqual (#PCDATA | include | iterate | isParameterPresent | isNotParameterPresent | isEmpty | isNotEmpty | isNotNull | isNull | isNotEqual | isEqual | isGreaterThan | isGreaterEqual | isLessThan | isLessEqual | isPropertyAvailable | isNotPropertyAvailable)*> 
          <!ATTLIST isNotEqual >
          prepend CDATA #IMPLIED 
          open CDATA #IMPLIED 
          close CDATA #IMPLIED 
          property CDATA #IMPLIED 
          removeFirstPrepend (true|false) #IMPLIED 
          compareProperty CDATA #IMPLIED 
          compareValue CDATA #IMPLIED 

          <!ELEMENT isGreaterThan (#PCDATA | include | iterate | isParameterPresent | isNotParameterPresent | isEmpty | isNotEmpty | isNotNull | isNull | isNotEqual | isEqual | isGreaterThan | isGreaterEqual | isLessThan | isLessEqual | isPropertyAvailable | isNotPropertyAvailable)*> 
          <!ATTLIST isGreaterThan >
          prepend CDATA #IMPLIED 
          open CDATA #IMPLIED 
          close CDATA #IMPLIED 
          property CDATA #IMPLIED 
          removeFirstPrepend (true|false) #IMPLIED 
          compareProperty CDATA #IMPLIED 
          compareValue CDATA #IMPLIED 

          <!ELEMENT isGreaterEqual (#PCDATA | include | iterate | isParameterPresent | isNotParameterPresent | isEmpty | isNotEmpty | isNotNull | isNull | isNotEqual | isEqual | isGreaterThan | isGreaterEqual | isLessThan | isLessEqual | isPropertyAvailable | isNotPropertyAvailable)*> 
          <!ATTLIST isGreaterEqual >
          prepend CDATA #IMPLIED 
          open CDATA #IMPLIED 
          close CDATA #IMPLIED 
          property CDATA #IMPLIED 
          removeFirstPrepend (true|false) #IMPLIED 
          compareProperty CDATA #IMPLIED 
          compareValue CDATA #IMPLIED 

          <!ELEMENT isLessThan (#PCDATA | include | iterate | isParameterPresent | isNotParameterPresent | isEmpty | isNotEmpty | isNotNull | isNull | isNotEqual | isEqual | isGreaterThan | isGreaterEqual | isLessThan | isLessEqual | isPropertyAvailable | isNotPropertyAvailable)*> 
          <!ATTLIST isLessThan >
          prepend CDATA #IMPLIED 
          open CDATA #IMPLIED 
          close CDATA #IMPLIED 
          property CDATA #IMPLIED 
          removeFirstPrepend (true|false) #IMPLIED 
          compareProperty CDATA #IMPLIED 
          compareValue CDATA #IMPLIED 

          <!ELEMENT isLessEqual (#PCDATA | include | iterate | isParameterPresent | isNotParameterPresent | isEmpty | isNotEmpty | isNotNull | isNull | isNotEqual | isEqual | isGreaterThan | isGreaterEqual | isLessThan | isLessEqual | isPropertyAvailable | isNotPropertyAvailable)*> 
          <!ATTLIST isLessEqual >
          prepend CDATA #IMPLIED 
          open CDATA #IMPLIED 
          close CDATA #IMPLIED 
          property CDATA #IMPLIED 
          removeFirstPrepend (true|false) #IMPLIED 
          compareProperty CDATA #IMPLIED 
          compareValue CDATA #IMPLIED 

          <!ELEMENT isEmpty (#PCDATA | include | iterate | isParameterPresent | isNotParameterPresent | isEmpty | isNotEmpty | isNotNull | isNull | isNotEqual | isEqual | isGreaterThan | isGreaterEqual | isLessThan | isLessEqual | isPropertyAvailable | isNotPropertyAvailable)*> 
          <!ATTLIST isEmpty >
          prepend CDATA #IMPLIED 
          open CDATA #IMPLIED 
          close CDATA #IMPLIED 
          property CDATA #IMPLIED 
          removeFirstPrepend (true|false) #IMPLIED 

          <!ELEMENT isNotEmpty (#PCDATA | include | iterate | isParameterPresent | isNotParameterPresent | isEmpty | isNotEmpty | isNotNull | isNull | isNotEqual | isEqual | isGreaterThan | isGreaterEqual | isLessThan | isLessEqual | isPropertyAvailable | isNotPropertyAvailable)*> 
          <!ATTLIST isNotEmpty >
          prepend CDATA #IMPLIED 
          open CDATA #IMPLIED 
          close CDATA #IMPLIED 
          property CDATA #IMPLIED 
          removeFirstPrepend (true|false) #IMPLIED 

          <!ELEMENT isParameterPresent (#PCDATA | include | iterate | isParameterPresent | isNotParameterPresent | isEmpty | isNotEmpty | isNotNull | isNull | isNotEqual | isEqual | isGreaterThan | isGreaterEqual | isLessThan | isLessEqual | isPropertyAvailable | isNotPropertyAvailable)*> 
          <!ATTLIST isParameterPresent >
          prepend CDATA #IMPLIED 
          open CDATA #IMPLIED 
          close CDATA #IMPLIED 
          removeFirstPrepend (true|false) #IMPLIED 

          <!ELEMENT isNotParameterPresent (#PCDATA | include | iterate | isParameterPresent | isNotParameterPresent | isEmpty | isNotEmpty | isNotNull | isNull | isNotEqual | isEqual | isGreaterThan | isGreaterEqual | isLessThan | isLessEqual | isPropertyAvailable | isNotPropertyAvailable)*> 
          <!ATTLIST isNotParameterPresent >
          prepend CDATA #IMPLIED 
          open CDATA #IMPLIED 
          close CDATA #IMPLIED 
          removeFirstPrepend (true|false) #IMPLIED 

          <!ELEMENT iterate (#PCDATA | include | iterate | isParameterPresent | isNotParameterPresent | isEmpty | isNotEmpty | isNotNull | isNull | isNotEqual | isEqual | isGreaterThan | isGreaterEqual | isLessThan | isLessEqual | isPropertyAvailable | isNotPropertyAvailable)*> 
          <!ATTLIST iterate >
          prepend CDATA #IMPLIED 
          property CDATA #IMPLIED 
          removeFirstPrepend (true|false|iterate) #IMPLIED 
          open CDATA #IMPLIED 
          close CDATA #IMPLIED 
          conjunction CDATA #IMPLIED 
          > 

          posted on 2012-09-20 00:54 奮斗成就男人 閱讀(982) 評論(0)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 托里县| 阿克陶县| 九龙县| 孝义市| 武乡县| 甘谷县| 柏乡县| 耒阳市| 定安县| 南京市| 米脂县| 商都县| 灵丘县| 达拉特旗| 从江县| 凤山县| 云林县| 额济纳旗| 浦江县| 兴山县| 平陆县| 龙泉市| 收藏| 昭觉县| 枞阳县| 隆德县| 萨迦县| 长乐市| 酉阳| 施甸县| 张家港市| 方山县| 赤水市| 通化县| 井研县| 米脂县| 清流县| 平山县| 仁布县| 阿巴嘎旗| 仙游县|