diff --git a/src/main/java/com/lanyuanxiaoyao/service/template/controller/SimpleControllerSupport.java b/src/main/java/com/lanyuanxiaoyao/service/template/controller/SimpleControllerSupport.java index 2c39c16..ed365e5 100644 --- a/src/main/java/com/lanyuanxiaoyao/service/template/controller/SimpleControllerSupport.java +++ b/src/main/java/com/lanyuanxiaoyao/service/template/controller/SimpleControllerSupport.java @@ -7,6 +7,7 @@ import java.util.List; import java.util.Map; import java.util.function.Function; import lombok.extern.slf4j.Slf4j; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -112,6 +113,7 @@ public abstract class SimpleControllerSupport 返回保存后的实体ID * @throws Exception 保存过程中可能抛出的异常 */ + @Transactional(rollbackFor = Throwable.class) @PostMapping(SAVE) @Override public GlobalResponse save(@RequestBody SAVE_ITEM item) throws Exception { @@ -125,6 +127,7 @@ public abstract class SimpleControllerSupport 返回实体列表 * @throws Exception 查询过程中可能抛出的异常 */ + @Transactional(readOnly = true) @GetMapping(LIST) @Override public GlobalResponse> list() throws Exception { @@ -152,6 +155,7 @@ public abstract class SimpleControllerSupport 返回符合条件的实体列表 * @throws Exception 查询过程中可能抛出的异常 */ + @Transactional(readOnly = true) @PostMapping(LIST) @Override public GlobalResponse> list(@RequestBody Query query) throws Exception { @@ -181,6 +185,7 @@ public abstract class SimpleControllerSupport 返回实体详情 * @throws Exception 查询过程中可能抛出的异常 */ + @Transactional(readOnly = true) @GetMapping(DETAIL) @Override public GlobalResponse detail(@PathVariable("id") Long id) throws Exception { @@ -195,6 +200,7 @@ public abstract class SimpleControllerSupport 返回删除结果 * @throws Exception 删除过程中可能抛出的异常 */ + @Transactional(rollbackFor = Throwable.class) @GetMapping(REMOVE) @Override public GlobalResponse remove(@PathVariable("id") Long id) throws Exception {