ShardingJDBC不支持批量插入的一种解决办法
时间:2021-07-01 10:21:17
帮助过:4人阅读
public class UserManager
implements ApplicationContextAware {
private static ApplicationContext applicationContext;
@Autowired
private UserDao UserDao;
public void createUseres(List<User> UserList) {
DefaultTransactionDefinition definition =
new DefaultTransactionDefinition();
definition.
setPropagationBehavior(TransactionDefinition.
PROPAGATION_REQUIRES_NEW);
definition.
setIsolationLevel(TransactionDefinition.
ISOLATION_READ_COMMITTED);
DataSourceTransactionManager transactionManager = (DataSourceTransactionManager)
applicationContext.
getBean(
"transactionManager");
TransactionStatus transactionStatus = transactionManager.
getTransaction(definition);
for (User User : UserList) {
//UserDao有create方法,单条插入
applicationContext.
getBean(UserDao.
class).
create(User);
}
transactionManager.
commit(transactionStatus);
}
@Override
public void setApplicationContext(ApplicationContext ac)
throws BeansException {
applicationContext = ac;
}
}
ShardingJDBC不支持批量插入的一种解决办法
标签:new tis value nts private 方法 override ted efi