欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

mybatis 批量將list數(shù)據(jù)插入到數(shù)據(jù)庫的實(shí)現(xiàn)

 更新時(shí)間:2020年07月03日 10:58:19   作者:悟世君子  
這篇文章主要介紹了mybatis 批量將list數(shù)據(jù)插入到數(shù)據(jù)庫的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

隨著業(yè)務(wù)需要,有時(shí)我們需要將數(shù)據(jù)批量添加到數(shù)據(jù)庫,mybatis提供了將list集合循環(huán)添加到數(shù)據(jù)庫的方法。具體實(shí)現(xiàn)代碼如下:

1、mapper層中創(chuàng)建 insertForeach(List < Fund > list) 方法,返回值是批量添加的數(shù)據(jù)條數(shù)

 package com.center.manager.mapper;
 import java.util.List;
 import org.apache.ibatis.annotations.Mapper;
 import com.center.manager.entity.Fund;
 @Mapper
 public interface FundMapper {
 
 int insertForeach(List<Fund> list);
 }

Fund類代碼如下:

 package com.center.manager.entity;
 import java.util.Date;

 public class Fund {

  private String id;
 
 private String fundName;  
 
 private String fundCode;  
 
 private String dateX;   
 
 private String dataY;   

  private String remarks; 
 
 private String createBy; 
 
 private Date createDate; 
 
 private String updateBy; 
 
 private Date updateDate; 
 
 private String delFlag; 

  public String getId() {
 return id;
 }

 public void setId(String id) {
 this.id = id;
 }
 
 public String getFundName() {
 return fundName;
 }

 public void setFundName(String fundName) {
 this.fundName = fundName;
 }

 public String getFundCode() {
 return fundCode;
 }

 public void setFundCode(String fundCode) {
 this.fundCode = fundCode;
 }

 public String getDateX() {
 return dateX;
 }

 public void setDateX(String dateX) {
 this.dateX = dateX;
 }

 public String getDataY() {
 return dataY;
 }

 public void setDataY(String dataY) {
 this.dataY = dataY;
 }

  public String getRemarks() {
 return remarks;
 }

 public void setRemarks(String remarks) {
 this.remarks = remarks;
 }

 public String getCreateBy() {
 return createBy;
 }

 public void setCreateBy(String createBy) {
 this.createBy = createBy;
 }

 public Date getCreateDate() {
 return createDate;
 }

 public void setCreateDate(Date createDate) {
 this.createDate = createDate;
 }

 public String getUpdateBy() {
 return updateBy;
 }

 public void setUpdateBy(String updateBy) {
 this.updateBy = updateBy;
 }

 public Date getUpdateDate() {
 return updateDate;
 }

 public void setUpdateDate(Date updateDate) {
 this.updateDate = updateDate;
 }

 public String getDelFlag() {
 return delFlag;
 }

 public void setDelFlag(String delFlag) {
 this.delFlag = delFlag;
 }

 }

2、mybatis的xml文件中的insert語句如下:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.center.manager.mapper.FundMapper">

 <insert id="insertForeach" parameterType="java.util.List" useGeneratedKeys="false">
  insert into fund
  ( id,fund_name,fund_code,date_x,data_y,create_by,create_date,update_by,update_date,remarks,del_flag)
  values
  <foreach collection="list" item="item" index="index" separator=",">
  (
   #{item.id},
   #{item.fundName},
   #{item.fundCode},
   #{item.dateX},
   #{item.dataY},
   #{item.createBy},
   #{item.createDate},
   #{item.updateBy},
   #{item.updateDate},
   #{item.remarks},
   #{item.delFlag}
  )
   </foreach> 
 </insert> 
</mapper>

到此這篇關(guān)于mybatis 批量將list數(shù)據(jù)插入到數(shù)據(jù)庫的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)mybatis 批量list插入到數(shù)據(jù)庫內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論