乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Mybatis 插入與批量插入以及多參數(shù)批量刪除

       昵稱9283147 2017-01-22

      實體類:

      復制代碼
      import java.io.Serializable;
      public class AttachmentTable implements Serializable {
          private static final long serialVersionUID = 8325882509007088323L;
          private Integer id;
          // 附件名稱
          private String name;
          // 日志ID
          private Integer logid;
          // 附件URL
          private String url;
      
          // getter/setter.......
      }
      復制代碼

      Mapper接口:

      復制代碼
      import java.util.List;
      import model.AttachmentTable;
      public interface AttachmentTableMapper {
        int insert(AttachmentTable record);
        void insertByBatch(List<AttachmentTable> attachmentTables); }
      復制代碼

      Mapper.xml:

      復制代碼
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE mapper PUBLIC "-////DTD Mapper 3.0//EN" "http:///dtd/mybatis-3-mapper.dtd">
      <mapper namespace="mapper.AttachmentTableMapper">
          <resultMap id="BaseResultMap" type="model.AttachmentTable">
              <id column="id" jdbcType="INTEGER" property="id" />
              <result column="name" jdbcType="VARCHAR" property="name" />
              <result column="logID" jdbcType="INTEGER" property="logid" />
          </resultMap>
          <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="model.AttachmentTable">
              <result column="url" jdbcType="LONGVARCHAR" property="url" />
          </resultMap>
          <sql id="Base_Column_List">
              id, name, logID
          </sql>
          <sql id="Blob_Column_List">
              url
          </sql>
          <insert id="insert" parameterType="model.AttachmentTable">
              insert into attachment_table (id, name, logID,url)
              values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{logid,jdbcType=INTEGER},#{url,jdbcType=LONGVARCHAR})
          </insert>
          <insert id="insertByBatch" parameterType="java.util.List">
              insert into attachment_table (name, logID,url)
              values
              <foreach collection="list" item="item" index="index" separator=",">
                  (#{item.name,jdbcType=VARCHAR}, #{item.logid,jdbcType=INTEGER},#{item.url,jdbcType=LONGVARCHAR})
              </foreach>
          </insert>
      </mapper>
      復制代碼

      【注:標紅的地方是需要注意的地方,我第一次做時直接“#{name,jdbcType=VARCHAR}”,沒有加前綴“item”,導致報錯“找不到name”】

       (二)多參數(shù)批量刪除示例

      package com.vrv.linkdood.app.workreport.demomodule.mapper;import org.apache.ibatis.annotations.Param;public interface AttachmentTableMapper {
          void deleteByLogIdAndNames(@Param("logid") Integer logID, @Param("names") String[] names);
      }
      復制代碼
          <delete id="deleteByLogIdAndNames">
              delete from attachment_table
              where logid = #{logid,jdbcType=INTEGER} AND NAME IN
              <foreach collection="names" item="item" index="index" open="(" close=")" separator=",">
                  #{item}
              </foreach>
          </delete>
      復制代碼

       

      復制代碼
      屬性 描述
      item 循環(huán)體中的具體對象。支持屬性的點路徑訪問,如item.age,item.info.details。
      具體說明:在list和數(shù)組中是其中的對象,在map中是value。
      該參數(shù)為必選。
      collection

      要做foreach的對象,作為入?yún)r,List<?>對象默認用list代替作為鍵,數(shù)組對象有array代替作為鍵,Map對象沒有默認的鍵。
      當然在作為入?yún)r可以使用@Param("keyName")來設置鍵,設置keyName后,list,array將會失效。 除了入?yún)⑦@種情況外,還有一種作為參數(shù)對象的某個字段的時候。舉個例子:
      如果User有屬性List ids。入?yún)⑹荱ser對象,那么這個collection = "ids"
      如果User有屬性Ids ids;其中Ids是個對象,Ids有個屬性List id;入?yún)⑹荱ser對象,那么collection = "ids.id"
      上面只是舉例,具體collection等于什么,就看你想對那個元素做循環(huán)。
      該參數(shù)為必選。

      separator 元素之間的分隔符,例如在in()的時候,separator=","會自動在元素中間用“,“隔開,避免手動輸入逗號導致sql錯誤,如in(1,2,)這樣。該參數(shù)可選。
      open foreach代碼的開始符號,一般是(和close=")"合用。常用在in(),values()時。該參數(shù)可選。
      close foreach代碼的關閉符號,一般是)和open="("合用。常用在in(),values()時。該參數(shù)可選。
      index 在list和數(shù)組中,index是元素的序號,在map中,index是元素的key,該參數(shù)可選。
       
      復制代碼

        本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多