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)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 大城县| 茶陵县| 凌海市| 汕头市| 青岛市| 河间市| 乐都县| 金溪县| 正定县| 修水县| 黎川县| 犍为县| 闸北区| 广丰县| 博兴县| 沾化县| 乐平市| 枝江市| 伊宁县| 榕江县| 河北区| 库车县| 桐柏县| 竹溪县| 嘉善县| 屯门区| 会理县| 武平县| 灯塔市| 潮州市| 长岭县| 洛隆县| 阜宁县| 陆河县| 西吉县| 新巴尔虎左旗| 广宗县| 闸北区| 信阳市| 韶关市| 措勤县|