• Ibatis批量处理


    1.插入

        <insert id="insTable"  resultClass="int">
          INSERT INTO [dbo].[table]
          ([Id]
          ,[FId],[IsDel],[CreateTime]
         )
          VALUES
          <iterate conjunction="," open="" close="">
            (#[].Id#
            ,#[].FId#
          
            ,0
            ,GETDATE()
           )
          </iterate>
        </insert>

    2.读取

        <select id="queryTable" resultMap="Table" parameterClass="List">
          select Id, FId, CreateTime
          from  Table (nolock) where IsDel=1 and [Id] in   
          <iterate open="(" close=")" conjunction=",">   
            #[]#   
          </iterate>   
        </select>

    3.修改

     <update id="updateTable" parameterClass="list">
           begin
          <iterate conjunction="">
            update TABLE 
            set
            Fid=#[].FId#     
            where id = #[].Id#;     
          </iterate>
          end;    
      </update> 
                    var tables = new List<Table>()
                    {
                        {new Table() {Id = 1, FId = "100"}},
                        {new Table() {Id = 2, FId = "102"}},
                    };
                    this.mapper.Update("updateTable", tables);

    4.删除 

    <delete id="delTable"  parameterClass="List">
          delete      
          from TABLE
          where id in    
          <iterate conjunction="," open="(" close=")">
            #[]#
          </iterate>
    </delete>
                    var ids=new List<int>(){2,3,4};
                    this.mapper.Delete("delTable", ids);

    5.类里字段列表插入(注意iterate 里多了一个property )

    <insert id="insSaleOrderDetails" parameterClass="SaleOrderDetailModel" resultClass="int">
          INSERT INTO [dbo].[SaleDetail]
          (
          [OrderId]
          ,[PId]
          ,[Price]
          ,[Quantity]
          ,[Amount]
          ,[CreateDate]
          ,[CreateTime]
          ,[Creator]
          ,[IsDel]
          )
          VALUES
          <iterate conjunction="," open="" close="" property="Details">
            (#SaleId#
            ,#Details[].PId#
            ,#Details[].Price#
            ,#Details[].Quantity#
            ,#Details[].Amount#
            ,getdate()
            ,getdate()
            ,#Creator#
            ,0
            )
          </iterate>
           
        </insert>

    6.ibatis的比较运算

    <isEqual> 相等。 
    <isNotEqual> 不等。 
    <isGreaterThan> 大于 
    <isGreaterEqual> 大于等于 
    <isLessThan> 小于 
    <isLessEqual> 小于等于 
    
    <isEqual property="Status" compareValue="1"> 
    and Status>0
    </isEqual> 
    
    <isEqual property="sort_onlinetime" compareValue="asc"> 
    order by u.online_time asc 
    </isEqual> 

    7.直接传入一个List

    <!--列表查询需显示内容-->
        <select id ="qryDataList"  parameterClass="list" resultClass="DataModel">
          select *
          from DataConfig a (NOLOCK) join data b  (NOLOCK)
          on a.dataid=b.id
          where a.isdel=0 and b.isdel=0
          
          <isNotNull prepend="AND">
            ModuleId in 
             <iterate  conjunction="," open="(" close=")">
              #[]#
            </iterate>
        
          </isNotNull>
        </select>
  • 相关阅读:
    基于I2C总线的MPU6050学习笔记
    基于I2C总线的0.96寸OLED显示屏驱动
    I2C总线协议的软件模拟实现方法
    I2C总线通讯协议
    Exynos4412从SD卡启动的简单网络文件系统制作
    多版本 PHP 环境下,使用指定版本运行composer
    腾讯云服务器 lnmp 开启 MySQL 远程访问权限
    MySQL添加新用户和新增权限
    Laravel 框架创建软链接
    Git 保存登录凭证
  • 原文地址:https://www.cnblogs.com/zhshlimi/p/6736992.html
Copyright © 2020-2023  润新知