Let spirit guide you

          thinking in life.

          常用鏈接

          統計

          API

          Forum

          Site

          WiKi

          最新評論

          ibatis sqlmap dynamic multiply condition

          map.put("username", "ACID");
          // map.put("firstName", "XYX");
          map.put("firstName", "");
          // map.put("lastName", "bb");
          map.put("lastName", "");
          // map.put("status","OK");
          map.put("status","");
          LinkedList emaillist=new LinkedList();
          emaillist.add("yahoo");
          emaillist.add("acid");
          map.put("emaillist",emaillist);
          try {
          // return this.getSqlMapClient().queryForList("getAccountNameListByMultiplyConditionsAnd",map);
          // return this.getSqlMapClient().queryForList("getAccountNameListByMultiplyConditionsOR",map);
          return this.getSqlMapClient().queryForList("getAccountNameListByMultiplyConditionsAndOR",map);
          // return this.getSqlMapClient().queryForList("getAccountNameListByMultiplyConditionsNested",map);
          } catch (SQLException e) {
          e.printStackTrace();
          }
          return null;
          sqlmap:
              <!-- =========================================================== -->
              <!-- 條件語句嵌套-->
              <!-- =========================================================== -->
              <!--    如果都不是空的:那么構造出來的sql是:  select userid as value from account        where   firstname=?     and(   lastname=?    or status=? )    -->
              <!--    如果lastName和status都是空的:那么構造出來的sql是:  select userid as value from account        where           firstname=?            and   ( 1=1      )        -->
              <!--   如果status都是空的:那么構造出來的sql是:  select userid as value from account        where             firstname=?     and    ( lastname=?    )       -->
              <!--   如果lastName都是空的:那么構造出來的sql是: select userid as value from account        where        firstname=?        and   ( 1=1       or       status=?  )         -->
              
              <!--      如果firstName為空:那么構造出來的sql是: select userid as value from account        where         ( lastname=?    or     status=?  )           -->
              <!--      如果都是為空:那么構造出來的sql是:  select userid as value from account        where         1=1               and   ( 1=1     )             -->
              <select id="getAccountNameListByMultiplyConditionsAndOR" resultClass="string" parameterClass="java.util.Map">
              select userid as value from account  
               <dynamic prepend="where" >
                     <isNotEmpty prepend="and" property="firstName" >
                       <![CDATA[
                    firstname=#firstName#
                          ]]>
          </isNotEmpty>
          <isEmpty property="firstName">
                     <![CDATA[
                          1=1 
                          ]]>
                     </isEmpty>
                     <isNotEmpty prepend="and" property="lastName">
                     <![CDATA[
                          ( lastname=#lastName#
                          ]]>
                     </isNotEmpty>
                     <isEmpty property="lastName">
                     <![CDATA[
                          and   ( 1=1 
                          ]]>
                     </isEmpty>
                     <isNotEmpty prepend="or" property="status">
                     <![CDATA[
                          status=#status#  )
                          ]]>
                     </isNotEmpty>
                     <isEmpty property="status">
                     <![CDATA[
                           )
                          ]]>
                     </isEmpty>
                      
          <isNotEmpty   prepend="and"  property="emaillist">
                    <iterate prepend="and"   property="emaillist"    conjunction="or" >
          email=#emaillist[]#
                    </iterate>
                   
                    </isNotEmpty>
               </dynamic>
            </select>

          posted on 2008-12-08 20:01 cary 閱讀(872) 評論(0)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 时尚| 嘉定区| 丰台区| 高唐县| 汤原县| 天柱县| 襄樊市| 大庆市| 雷波县| 林芝县| 吴江市| 淮阳县| 加查县| 彰化县| 西丰县| 高唐县| 连城县| 仪陇县| 洛川县| 苏尼特左旗| 娄烦县| 富阳市| 阿瓦提县| 台北市| 阿坝县| 乐平市| 镶黄旗| 芷江| 札达县| 阜宁县| 南皮县| 邛崃市| 万全县| 临武县| 和林格尔县| 克拉玛依市| 额敏县| 浮梁县| 确山县| 南阳市| 永济市|