jpa在批量添加的时候,存储慢如何解决问题。

spring.datasource.url = jdbc:mysql://xxxxxxxx:xxxx/xxxxx?useSSL=false&useUnicode=true&characterEncoding=utf-8&rewriteBatchedStatements=true&autoReconnect=true
在这里插入图片描述
入口下加@EnableTransactionManagement
@SpringBootApplication
@EnableTransactionManagement
service实现类下加
@Service
@Transactional
![在这里插入图片描述](https://img-blog.csdnimg.cn/20191220111053531.png引用
@Autowired
private NamedParameterJdbcTemplate namedParameterJdbcTempla
在这里插入图片描述
sql语句这样写:根据自己的字段多少来写格式不能变下面是一个demo
String sql = “INSERT INTO xxxx(id,name,age) VALUES (:id,:name,:age)”;

List uparChnMulMinList = (List) map.get(“uparChnMulMinList”);
SqlParameterSource[] batch = SqlParameterSourceUtils.createBatch(uparChnMulMinList.toArray());
namedParameterJdbcTemplate.batchUpdate(sql, batch);
自定义的list:List
SqlParameterSourceUtils导入这个直接用,调用这个方法createBatch();

开启数据空批量配置:rewriteBatchedStatements=true
开启事务:@EnableTransactionManagement ,@Transactional
可以一试。

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值