Let spirit guide you

          thinking in life.

          常用鏈接

          統(tǒng)計

          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:
              <!-- =========================================================== -->
              <!-- 條件語句嵌套-->
              <!-- =========================================================== -->
              <!--    如果都不是空的:那么構(gòu)造出來的sql是:  select userid as value from account        where   firstname=?     and(   lastname=?    or status=? )    -->
              <!--    如果lastName和status都是空的:那么構(gòu)造出來的sql是:  select userid as value from account        where           firstname=?            and   ( 1=1      )        -->
              <!--   如果status都是空的:那么構(gòu)造出來的sql是:  select userid as value from account        where             firstname=?     and    ( lastname=?    )       -->
              <!--   如果lastName都是空的:那么構(gòu)造出來的sql是: select userid as value from account        where        firstname=?        and   ( 1=1       or       status=?  )         -->
              
              <!--      如果firstName為空:那么構(gòu)造出來的sql是: select userid as value from account        where         ( lastname=?    or     status=?  )           -->
              <!--      如果都是為空:那么構(gòu)造出來的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 閱讀(871) 評論(0)  編輯  收藏


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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 博野县| 南川市| 旌德县| 安庆市| 太仆寺旗| 视频| 淄博市| 新闻| 沾化县| 景洪市| 永昌县| 和林格尔县| 上林县| 洛川县| 红原县| 达孜县| 乡城县| 含山县| 来安县| 宿松县| 东乡| 宁夏| 五寨县| 皮山县| 安徽省| 余姚市| 南充市| 太仆寺旗| 荔波县| 黎城县| 巴中市| 明星| 黎川县| 洪雅县| 富蕴县| 石柱| 太湖县| 泗洪县| 黎川县| 龙南县| 雷州市|