Commit 2acf9bda by huangjinxin

fix:实验代码

1 parent 2c2ec011
...@@ -43,7 +43,7 @@ public class RoleController implements IRole { ...@@ -43,7 +43,7 @@ public class RoleController implements IRole {
@Override @Override
public Result<RoleInfo> deleteRole2(@Validated RoleInfo roleInfo) { public Result<RoleInfo> deleteRole2(@Validated RoleInfo roleInfo) {
roleInfo = roleService.addRole(roleInfo); roleInfo = roleService.deleteRole2(roleInfo);
return Result.success(roleInfo); return Result.success(roleInfo);
} }
......
...@@ -24,8 +24,12 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -24,8 +24,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
...@@ -59,7 +63,8 @@ public class RoleService { ...@@ -59,7 +63,8 @@ public class RoleService {
@Autowired @Autowired
RedisService redisService; RedisService redisService;
@Autowired
private DataSourceTransactionManager dataSourceTransactionManager;
/** /**
* 失效时间ms * 失效时间ms
*/ */
...@@ -128,6 +133,11 @@ public class RoleService { ...@@ -128,6 +133,11 @@ public class RoleService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public RoleInfo deleteRole2(RoleInfo roleInfo) { public RoleInfo deleteRole2(RoleInfo roleInfo) {
DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition();
defaultTransactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
TransactionStatus transaction = dataSourceTransactionManager.getTransaction(defaultTransactionDefinition);
String name = roleInfo.getName(); String name = roleInfo.getName();
String createdBy = roleInfo.getCreatedBy(); String createdBy = roleInfo.getCreatedBy();
String notes = roleInfo.getNotes(); String notes = roleInfo.getNotes();
...@@ -148,8 +158,17 @@ public class RoleService { ...@@ -148,8 +158,17 @@ public class RoleService {
roleResourceDao.save(roleResourceEntity); roleResourceDao.save(roleResourceEntity);
} }
} }
roleDao.flush();
log.info("新增角色信息:" + JSONObject.toJSONString(roleInfo)); log.info("新增角色信息:" + JSONObject.toJSONString(roleInfo));
try {
// 业务代码
// 手动提交事务
dataSourceTransactionManager.commit(transaction);
} catch (Exception e) {
// 手动回滚事务
dataSourceTransactionManager.rollback(transaction);
}
return roleInfo; return roleInfo;
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!