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

郑州网站设计见效快wordpress short_open_tag

郑州网站设计见效快,wordpress short_open_tag,wordpress站点地图样式,韩国女足还能出线吗项目基于优秀开源项目:若依 项目背景:项目中牵扯到数据批量导入,为提高性能,先考虑将MybatisPlus伪批量插入增强为真实批量插入 MybatisPlus源码: MybatisPlus支持批量插入,但是跟踪源码发现底层是将批量…

项目基于优秀开源项目:若依

项目背景:项目中牵扯到数据批量导入,为提高性能,先考虑将MybatisPlus伪批量插入增强为真实批量插入

MybatisPlus源码:

MybatisPlus支持批量插入,但是跟踪源码发现底层是将批量插入的数据循环执行了N次单条插入:

IService源码:

    @Transactional(rollbackFor = {Exception.class})default boolean saveBatch(Collection<T> entityList) {return this.saveBatch(entityList, 1000);}boolean saveBatch(Collection<T> entityList, int batchSize);

ServiceImpl源码:

    @Transactional(rollbackFor = {Exception.class})public boolean saveBatch(Collection<T> entityList, int batchSize) {String sqlStatement = this.getSqlStatement(SqlMethod.INSERT_ONE);return this.executeBatch(entityList, batchSize, (sqlSession, entity) -> {sqlSession.insert(sqlStatement, entity);});}

底层支持增强改造:

1、创建自定义sql注入类:MySqlInjector.java
public class MySqlInjector extends DefaultSqlInjector {public MySqlInjector() {}@Overridepublic List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo);methodList.add(new InsertBatchSomeColumn(i -> i.getFieldFill() != FieldFill.UPDATE));return methodList;}}
2、创建自定义Mapper    MyBaseMapper.java
public interface MyBaseMapper<T> extends BaseMapper<T> {/*** 批量插入 仅适用于mysql** @param entityList 实体列表* @return 影响行数*/Integer insertBatchSomeColumn(Collection<T> entityList);
}

3、业务Mapper实现自定义的Mapper

@Repository
public interface TestMapper extends MyBaseMapper<Test>
{}
4、业务中批量插入,使用insertBatchSomeColumn函数
insertBatchSomeColumn(list);
5、新建MyBatisPlus配置类,将自定义sql注入   MybatisPlusConfig.java
@Configuration
public class MybatisPlusConfig {@Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor() {MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();//指定使用数据库类型interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));return interceptor;}@Beanpublic DefaultSqlInjector mySqlInjector() {return new MySqlInjector();}}

在使用默认MybatisPlus配置默认 sessionFactory时,以上即可

此处基于若依,需要将自定义sessionFactory设置为自定义sql注入器

配置文件位置,参考

framwork模块下config包MyBatisConfig

    @Beanpublic SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception{String typeAliasesPackage = env.getProperty("mybatis.typeAliasesPackage");String mapperLocations = env.getProperty("mybatis.mapperLocations");String configLocation = env.getProperty("mybatis.configLocation");typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage);VFS.addImplClass(SpringBootVFS.class);final MybatisSqlSessionFactoryBean sessionFactory = new MybatisSqlSessionFactoryBean();sessionFactory.setDataSource(dataSource);sessionFactory.setTypeAliasesPackage(typeAliasesPackage);sessionFactory.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ",")));sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));//自定义批量插入GlobalConfig globalConfig = new GlobalConfig();GlobalConfig.DbConfig dbConfig = new GlobalConfig.DbConfig();globalConfig.setDbConfig(dbConfig);globalConfig.setSqlInjector(new MySqlInjector());sessionFactory.setGlobalConfig(globalConfig);return sessionFactory.getObject();}

基于以上,大功告成。快去试试效果吧

http://www.yayakq.cn/news/999070/

相关文章:

  • 安微建设厅网站网站模块是什么意思
  • 用vs2008做的网站前台脚本是什么交换链接名词解释
  • 建筑人才网官方网站查询海口网上注册公司流程
  • 重庆奉节网站建设公司哪家专业wordpress查看图片插件
  • tomcat做网站wordpress 主题 字体
  • 女生做网站开发广告免费设计在线生成
  • 团购网站开发外贸网站contact
  • 校园微网站建设方案ppt模板wordpress 获取文章链接
  • 视频网站开发有哪些功能苏州百姓网免费发布信息网
  • 网页设计与制作论文1000字搜索引擎优化的步骤
  • 电商网站建设 问题 心得体会wordpress创建数据表
  • asp网站上一篇下一篇代码路桥网站制作
  • 外贸网站有必要吗做网站怎么做付费推广
  • 十天学会网站建设网络营销运营公司
  • 免费注册推广网站福建建设科技人才网站
  • 现在有什么新型建筑模板合肥seo搜索优化
  • 个人网站 jsp 域名空间国外大气网站
  • 谁有做网站的朋友的V信做网站买什么服务器 便宜
  • 北京汽车业务网站开发公司顺德网站建设找顺的
  • 电脑可以做网站主机么北京临沂商会网站建设
  • 网站建设交流平台网站的创建历程怎么写
  • 新手做网站详细步骤箱包网站建设策划报告
  • 手机网站与pc网站同步建设网站怎么提需求
  • 合肥市住房建设局网站网站的建设ppt
  • 泉州专业网站建设费用济南网络公司建站
  • 各类微网站建设网站开发设计大概多少费用
  • 哪个网站专做二手相机wordpress图片间隔
  • 关注公众号一单一结兼职app徐州自动seo
  • 手机网站永久免费制作手机网站如何做外链
  • 找深圳网站建设好用的建筑设计网站