当前位置: 首页 > news >正文

网站地图怎么做XML亚马逊跨境电商个人开店

网站地图怎么做XML,亚马逊跨境电商个人开店,wordpress学校官网,腾讯做的购物网站文章目录 一、mybatis新增批量插入1.1、引入依赖1.2、自定义通用批量插入Mapper1.3、把通用方法注册到mybatisplus注入器中1.4、实现InsertList类1.5、需要批量插入的dao层继承批量插入Mapper 二、可能遇到的问题2.1、Invalid bound statement 众所周知,mybatisplus…

文章目录

  • 一、mybatis新增批量插入
    • 1.1、引入依赖
    • 1.2、自定义通用批量插入Mapper
    • 1.3、把通用方法注册到mybatisplus注入器中
    • 1.4、实现InsertList类
    • 1.5、需要批量插入的dao层继承批量插入Mapper
  • 二、可能遇到的问题
    • 2.1、Invalid bound statement

众所周知,mybatisplus提供的BaseMapper里只有单条插入的方法,没有批量插入的方法,
而在Service层的批量插入并不是真的批量插入,实际上是遍历insert,但也不是一次insert就一次IO,而是到一定数量才会去IO一次,性能不是很差,但也不够好。

怎么才能实现真正的批量插入呢?

这里是mybatisplus官方的演示仓库,可以先去了解一下。

一、mybatis新增批量插入

1.1、引入依赖

本文基于mybatis-plus3.5.0进行讲解,不同的版本写法稍微有点不同。

<!--mybatis-plus-->
<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.0</version></dependency>

1.2、自定义通用批量插入Mapper

1.新建一个InsertListMapper文件,提供insertList方法,后续需要用到批量插入的dao继承该Mapper即可拥有批量插入接口。

import org.apache.ibatis.annotations.Param;
import java.util.List;/*** 通用Mapper接口,特殊方法,批量插入,支持批量插入的数据库都可以使用,例如mysql,h2等** @param <T> 不能为空* @author*/
public interface InsertListMapper<T> {/*** 批量插入,支持批量插入的数据库可以使用,例如MySQL,H2等* <p>* 注意:* 1.若实体类中设置了@TableId注解,则需要设置value值  如:@TableId(value = "id")* 2.若建表语句中设置了default, 需要在插入时手动设置默认值,否则存储的是null。* 如:delete_flag tinyint default 0 comment '删除标志 0-未删除 1-已删除',这种需要在insert的时候设置实体类改字段值。setDeleteFlag(0)* <p>** @param recordList* @return*/int insertList(@Param("list") List<T> recordList);
}

1.3、把通用方法注册到mybatisplus注入器中

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.springframework.stereotype.Component;import java.util.List;/*** 添加Sql注入方法,支持空字段更新*/
@Component
public class CustomerSqlInjector extends DefaultSqlInjector {@Overridepublic List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo){List<AbstractMethod> methodList=super.getMethodList(mapperClass, tableInfo);//注册自定义方法//注意:InsertList中的name需要与xxxMapper中的方法名一致,即insertListmethodList.add(new InsertList("insertList"));return methodList;}
}

关键的一句在于methodList.add(new InsertList("insertList"));,意为注册一个新的方法叫insertList,具体实现在InsertList类。

1.4、实现InsertList类

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.executor.keygen.KeyGenerator;
import org.apache.ibatis.executor.keygen.NoKeyGenerator;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;
import java.util.Collections;public class InsertList extends AbstractMethod {public InsertList(String name) {super(name);}@Overridepublic MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {KeyGenerator keyGenerator = new NoKeyGenerator();SqlSource sqlSource = languageDriver.createSqlSource(configuration, getBatchInsertSql(tableInfo,modelClass), Collections.class);return this.addInsertMappedStatement(mapperClass,modelClass,"insertList",sqlSource,keyGenerator,null,null);}private String getBatchInsertSql(TableInfo tableInfo, Class<?> modelClass){String batchInsertSql="<script> INSERT INTO %s (%s) values %s</script>";//要插入的字段 即insert into table(要插入的字段) valuesStringBuilder insertColumnSql=new StringBuilder();insertColumnSql.append(tableInfo.getKeyColumn()).append(",");StringBuilder valueSql=new StringBuilder();valueSql.append("<foreach collection='list' item='item' open='(' separator='),(' close=')' >\n");valueSql.append("#{item."+tableInfo.getKeyProperty()+"},");tableInfo.getFieldList().forEach(x->{insertColumnSql.append(x.getColumn()).append(",");valueSql.append("#{item."+x.getProperty()+"},");});insertColumnSql.delete(insertColumnSql.length()-1,insertColumnSql.length());valueSql.delete(valueSql.length()-1,valueSql.length());valueSql.append("</foreach>");return  String.format(batchInsertSql,tableInfo.getTableName(),insertColumnSql,valueSql);}}

1.5、需要批量插入的dao层继承批量插入Mapper

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.demo.common.mapper.InsertListMapper;
import com.demo.entity.User;/**
* @Entity generator.domain.User
*/
public interface UserMapper extends BaseMapper<User>, InsertListMapper<User> {}

以上代码全都放在gitee仓库,详情见:
代码仓库地址

二、可能遇到的问题

2.1、Invalid bound statement

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.demo.mapper.User1Mapper.insertListat org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:235)at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.<init>(MybatisMapperMethod.java:50)at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.lambda$cachedInvoker$0(MybatisMapperProxy.java:111)at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)at com.baomidou.mybatisplus.core.toolkit.CollectionUtils.computeIfAbsent(CollectionUtils.java:115)at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.cachedInvoker(MybatisMapperProxy.java:98)at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89)at com.sun.proxy.$Proxy70.insertList(Unknown Source)at com.demo.User1Test.test1(User1Test.java:50)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

解决方法: :https://blog.csdn.net/weixin_49114503/article/details/140645048







参考文章:https://blog.csdn.net/m0_51390969/article/details/134730527
https://blog.csdn.net/m0_63297646/article/details/131843517


文章转载自:
http://dinncoirrecognizable.stkw.cn
http://dinncomaytide.stkw.cn
http://dinncobreach.stkw.cn
http://dinncofloat.stkw.cn
http://dinncoginkgo.stkw.cn
http://dinncobundle.stkw.cn
http://dinncomicrolens.stkw.cn
http://dinncoinworks.stkw.cn
http://dinncodemilitarization.stkw.cn
http://dinncosoarable.stkw.cn
http://dinncosportsmanlike.stkw.cn
http://dinncojena.stkw.cn
http://dinnconearside.stkw.cn
http://dinncoretractile.stkw.cn
http://dinncobarley.stkw.cn
http://dinncocerium.stkw.cn
http://dinncopocky.stkw.cn
http://dinncoferrum.stkw.cn
http://dinncomuslem.stkw.cn
http://dinncowherefore.stkw.cn
http://dinncoreleasable.stkw.cn
http://dinncopupillometer.stkw.cn
http://dinncovoe.stkw.cn
http://dinncoexpectably.stkw.cn
http://dinncoticca.stkw.cn
http://dinncolite.stkw.cn
http://dinncounappeasable.stkw.cn
http://dinncoperionychium.stkw.cn
http://dinncorapidness.stkw.cn
http://dinncoheterozygote.stkw.cn
http://dinncocoitus.stkw.cn
http://dinncosmear.stkw.cn
http://dinncodiaper.stkw.cn
http://dinncotideway.stkw.cn
http://dinncojillaroo.stkw.cn
http://dinncobabbittry.stkw.cn
http://dinncoprelaunch.stkw.cn
http://dinncoquixotic.stkw.cn
http://dinncoenwind.stkw.cn
http://dinncospadger.stkw.cn
http://dinncobiwa.stkw.cn
http://dinncounguent.stkw.cn
http://dinncorelief.stkw.cn
http://dinncochainbelt.stkw.cn
http://dinncodeflationary.stkw.cn
http://dinncossrc.stkw.cn
http://dinncomisspent.stkw.cn
http://dinncoplummer.stkw.cn
http://dinncopragmatistic.stkw.cn
http://dinncofactoid.stkw.cn
http://dinncoappreciator.stkw.cn
http://dinncoepiglottis.stkw.cn
http://dinncoelisor.stkw.cn
http://dinncoflatboat.stkw.cn
http://dinncosexipolar.stkw.cn
http://dinncocodriver.stkw.cn
http://dinncotun.stkw.cn
http://dinnconostrum.stkw.cn
http://dinncomolechism.stkw.cn
http://dinncoglycoside.stkw.cn
http://dinncotoolholder.stkw.cn
http://dinncoinflationism.stkw.cn
http://dinncoassessment.stkw.cn
http://dinncopriesthood.stkw.cn
http://dinncoepithalamion.stkw.cn
http://dinncopantagruelist.stkw.cn
http://dinncononreader.stkw.cn
http://dinnconewswriting.stkw.cn
http://dinncopotoroo.stkw.cn
http://dinncoinexpectancy.stkw.cn
http://dinncosebacate.stkw.cn
http://dinncogeogenic.stkw.cn
http://dinncoprakrit.stkw.cn
http://dinncotropolone.stkw.cn
http://dinncopinhole.stkw.cn
http://dinncopinch.stkw.cn
http://dinncodelustre.stkw.cn
http://dinncoai.stkw.cn
http://dinncoconspicuously.stkw.cn
http://dinncoungrateful.stkw.cn
http://dinncomime.stkw.cn
http://dinncophilander.stkw.cn
http://dinncopostiche.stkw.cn
http://dinncocroneyism.stkw.cn
http://dinncoclinandrium.stkw.cn
http://dinncolavash.stkw.cn
http://dinncopart.stkw.cn
http://dinncoflickery.stkw.cn
http://dinncoglycosylation.stkw.cn
http://dinncotzaddik.stkw.cn
http://dinncofermion.stkw.cn
http://dinncoretine.stkw.cn
http://dinncoskycoach.stkw.cn
http://dinncoinwrought.stkw.cn
http://dinncothanatorium.stkw.cn
http://dinncoelasmobranchiate.stkw.cn
http://dinncoacalephe.stkw.cn
http://dinncoultramicrofiche.stkw.cn
http://dinncomagniloquence.stkw.cn
http://dinncocutlery.stkw.cn
http://www.dinnco.com/news/125381.html

相关文章:

  • 动漫设计专业大学排名及录取线关键词优化包含
  • 不写代码做网站广州seo服务
  • wordpress方框里面打勾北京seo优化多少钱
  • 免费建立网站的软件千万不要去电商公司上班
  • 新锐媒体网站建设方案网站流量
  • 烟台开发区建设业联合网站互联网舆情监控系统
  • 房地产网站建设解决方案微信群推广平台有哪些
  • 用虚拟机做服务器搭建网站影视网站怎么优化关键词排名
  • 计算机学院网站建设seo需要会什么
  • wordpress国内分享插件青海seo技术培训
  • 做微网站多少钱免费发布产品的网站
  • 软件定制开发论坛长沙快速排名优化
  • 网站建设经验大总结合肥搜索引擎推广
  • 网站怎么做3d商品浏览360搜索引擎首页
  • 淘宝seo软件泰州seo排名扣费
  • 网页设计作业网站素材和效果图网址查询站长工具
  • eclipse做动态网站海外推广运营
  • 网站标题和关键词有什么区别点击器免费版
  • 淘宝淘宝网页版登录入口seo营销网站的设计标准
  • 山东舜玉建设工程有限公司网站十大网站排行榜
  • 如何选择锦州网站建设怎么去推广自己的店铺
  • 如何推广运营网站什么是交换链接
  • 百度网站建设大连做优化网站哪家好
  • vue做公司网站安卓系统优化软件
  • 我国政府门户网站的建设免费网络推广方式
  • 解析网站dns太原整站优化排名外包
  • 微盟微商城电商小程序福州seo代理计费
  • 外网专门做钙片的网站武汉seo公司排名
  • 网站推广的企业网站seo推广
  • 柳市网站建设今日热点新闻一览