posts - 41, comments - 15, trackbacks - 0, articles - 1
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          ibatis in語句參數傳入方法

          Posted on 2012-02-03 10:11 yuhaibo736 閱讀(16611) 評論(1)  編輯  收藏
           第一種:傳入參數僅有數組
                 <select id="GetEmailList_Test"  resultClass="EmailInfo_">
                      select *
                      from MailInfo with (nolock)
                      where ID in
                          <iterate open="(" close=")" conjunction="," >
                              #[]#
                          </iterate>
                  </select>
          調用
                      string[] strValue = new string[] { "1", "2", "3" };
                      Reader.QueryForList<EmailInfoModel>("WebApp_Ibatisnet.dao.GetEmailList_Test", strValue );

                 第二種:傳入參數有數組,且有其他數據
                  <select id="GetEmailList_Test3" parameterClass="TestIn" resultClass="EmailInfo_">
                      select  top(#Count#)*
                      from MailInfo with (nolock)
                      where ID in
                      <iterate open="(" close=")" conjunction="," property="ArrValue" >
                          #ArrValue[]#
                      </iterate>
                  </select>
          調用
                      TestIn ti = new TestIn();
                      ti.Count = 1;
                      ti.ArrValue = strValue;
                      return Reader.QueryForList<EmailInfoModel>("WebApp_Ibatisnet.dao.GetEmailList_Test3", ti);
          實體類:
             public class TestIn
              {
                  private int count;
                  public int Count
                  {
                      get { return count; }
                      set { count = value; }
                  }
                  private string[] arrValue;
                  public string[] ArrValue
                  {
                      get { return arrValue; }
                      set { arrValue = value; }
                  }
              }

                 第三種:in后面的數據確定,使用string傳入
                  <select id="GetEmailList_Test2" parameterClass="TestIn" resultClass="EmailInfo_">
                      select *
                      from MailInfo with (nolock)
                      where ID in
                      ($StrValue$)
                  </select>
          調用
                          Reader.QueryForList<EmailInfoModel>("WebApp_Ibatisnet.dao.GetEmailList_Test2", "1,2,3");


          其他信息:
          Iterate的屬性:
          prepend -可被覆蓋的SQL語句組成部分,添加在語句的前面(可選)
          property -類型為java.util.List的用于遍歷的元素(必選)
          open -整個遍歷內容體開始的字符串,用于定義括號(可選)
          close -整個遍歷內容體結束的字符串,用于定義括號(可選)
          conjunction -每次遍歷內容之間的字符串,用于定義AND或OR(可選)
          <iterate>遍歷類型為java.util.List的元素。

          評論

          # re: ibatis in語句參數傳入方法  回復  更多評論   

          2012-05-11 16:43 by gaojingy
          12

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


          網站導航:
           
          主站蜘蛛池模板: 罗定市| 张家口市| 临朐县| 南通市| 左贡县| 得荣县| 克什克腾旗| 来凤县| 龙陵县| 鞍山市| 梨树县| 湖北省| 九龙县| 宜阳县| 高青县| 寻乌县| 获嘉县| 奇台县| 本溪| 同心县| 澄城县| 浙江省| 三都| 旬阳县| 开封市| 临夏市| 斗六市| 蒲城县| 肇东市| 长白| 郯城县| 博野县| 连平县| 仙居县| 淮阳县| 郎溪县| 邻水| 九龙城区| 渑池县| 高要市| 西城区|