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

网站会说话长沙优化网站推广

网站会说话,长沙优化网站推广,seo常规优化,汽车seo是什么意思项目基于优秀开源项目:若依 项目背景:项目中牵扯到数据批量导入,为提高性能,先考虑将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/278199/

相关文章:

  • dede资讯类网站模板wordpress模板首页图片
  • 专做特产的网站广州h5设计网站公司
  • 怎么创建一个博客网站室内设计公司职位
  • 中国建设银行青岛分行网站wordpress 压缩图片大小
  • 楚雄市网站建设公司郑州app网站公司
  • 静态网站怎么做留言板上海公司注册网上申请
  • 电脑上怎么做网站广州响应网站建设
  • 徐东网站建设公司在自己电脑上建设网站
  • 工商网站查询个人信息培训网站建设课程
  • 南阳做网站公司电话wordpress侧边栏缩略图
  • 惠州网站制作公司免费手机做网站
  • 网站建设整体设计思路临淄哪里做网站
  • 张店网站制作设计公司南宁做网店
  • 广州网站建设与网页设计可以免费学编程的网站
  • 益阳建站网站制作网站变成灰色
  • 网页制作代码淄博网站制作定制优化
  • 西安网站制作一般多少钱网站等保需要几年一做
  • 网站一个页面多少钱蜜蜂vp加速器七天试用
  • 找网站做外链是什么意思财务管理培训
  • 中国网站域名备案管理系统邯郸网站建设品牌加盟
  • 做文员的网站知乎织梦网站中的对话框怎摸做
  • 手机网站建设网怎么做一网站首页
  • 网站建设合同附加协议包括搜索引擎排名、网页标签优化、相关链接交换、网络广告投放等
  • 河南省住房和城乡建设厅网站确认书哪里有做网站推广
  • 东营建设信息网站wordpress识图搜索代码6
  • 丰泰建设集团有限公司网站微信网站建设信息
  • 做出网站迅雷2t免费空间活动
  • 中国建设银行招聘官网站wordpress后台怎么登陆
  • 外贸网店有哪些seo优化是什么
  • 网站建设预算明细百度登录个人中心