Commit 9f5553e6 by huangjinxin

fix:实验代码

1 parent 2acf9bda
...@@ -9,6 +9,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; ...@@ -9,6 +9,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*; import javax.persistence.*;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date; import java.util.Date;
/** /**
...@@ -54,9 +55,9 @@ public class RoleEntity implements Serializable { ...@@ -54,9 +55,9 @@ public class RoleEntity implements Serializable {
/** /**
* 创建时间 * 创建时间
*/ */
@Column(name = "CREATED_TIME") // @Column(name = "CREATED_TIME")
@CreatedDate @Column(name = "CREATED_TIME", nullable = false, updatable = false, columnDefinition = "timestamp default current_timestamp")
private Date createdTime; private LocalDateTime createdTime;
/** /**
* 更新人 * 更新人
*/ */
...@@ -65,9 +66,9 @@ public class RoleEntity implements Serializable { ...@@ -65,9 +66,9 @@ public class RoleEntity implements Serializable {
/** /**
* 更新时间 * 更新时间
*/ */
@Column(name = "UPDATED_TIME") // @Column(name = "UPDATED_TIME")
@LastModifiedDate @Column(name = "UPDATED_TIME", nullable = false, columnDefinition = "timestamp default current_timestamp on update current_timestamp")
private Date updatedTime; private LocalDateTime updatedTime;
/** /**
* 备注 * 备注
......
...@@ -31,6 +31,7 @@ import org.springframework.transaction.TransactionStatus; ...@@ -31,6 +31,7 @@ import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.DefaultTransactionDefinition; import org.springframework.transaction.support.DefaultTransactionDefinition;
import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
...@@ -63,8 +64,8 @@ public class RoleService { ...@@ -63,8 +64,8 @@ public class RoleService {
@Autowired @Autowired
RedisService redisService; RedisService redisService;
@Autowired // @Autowired
private DataSourceTransactionManager dataSourceTransactionManager; // private DataSourceTransactionManager dataSourceTransactionManager;
/** /**
* 失效时间ms * 失效时间ms
*/ */
...@@ -79,7 +80,7 @@ public class RoleService { ...@@ -79,7 +80,7 @@ public class RoleService {
RoleEntity roleEntity = new RoleEntity(); RoleEntity roleEntity = new RoleEntity();
roleEntity.setName(name); roleEntity.setName(name);
roleEntity.setCreatedBy(createdBy); roleEntity.setCreatedBy(createdBy);
roleEntity.setCreatedTime(new Date()); roleEntity.setCreatedTime(LocalDateTime.now());
roleEntity.setNotes(notes); roleEntity.setNotes(notes);
// RoleEntity roleEntity = assembleRole(roleInfo); // RoleEntity roleEntity = assembleRole(roleInfo);
log.info("新增角色入参:" + JSONObject.toJSONString(roleEntity)); log.info("新增角色入参:" + JSONObject.toJSONString(roleEntity));
...@@ -133,11 +134,6 @@ public class RoleService { ...@@ -133,11 +134,6 @@ 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();
...@@ -160,15 +156,6 @@ public class RoleService { ...@@ -160,15 +156,6 @@ public class RoleService {
} }
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!