perf: 增加事务处理
This commit is contained in:
@@ -7,6 +7,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
@@ -112,6 +113,7 @@ public abstract class SimpleControllerSupport<ENTITY extends SimpleEntity, SAVE_
|
|||||||
* @return GlobalResponse<Long> 返回保存后的实体ID
|
* @return GlobalResponse<Long> 返回保存后的实体ID
|
||||||
* @throws Exception 保存过程中可能抛出的异常
|
* @throws Exception 保存过程中可能抛出的异常
|
||||||
*/
|
*/
|
||||||
|
@Transactional(rollbackFor = Throwable.class)
|
||||||
@PostMapping(SAVE)
|
@PostMapping(SAVE)
|
||||||
@Override
|
@Override
|
||||||
public GlobalResponse<Long> save(@RequestBody SAVE_ITEM item) throws Exception {
|
public GlobalResponse<Long> save(@RequestBody SAVE_ITEM item) throws Exception {
|
||||||
@@ -125,6 +127,7 @@ public abstract class SimpleControllerSupport<ENTITY extends SimpleEntity, SAVE_
|
|||||||
* @return GlobalCrudResponse<LIST_ITEM> 返回实体列表
|
* @return GlobalCrudResponse<LIST_ITEM> 返回实体列表
|
||||||
* @throws Exception 查询过程中可能抛出的异常
|
* @throws Exception 查询过程中可能抛出的异常
|
||||||
*/
|
*/
|
||||||
|
@Transactional(readOnly = true)
|
||||||
@GetMapping(LIST)
|
@GetMapping(LIST)
|
||||||
@Override
|
@Override
|
||||||
public GlobalResponse<Map<String, Object>> list() throws Exception {
|
public GlobalResponse<Map<String, Object>> list() throws Exception {
|
||||||
@@ -152,6 +155,7 @@ public abstract class SimpleControllerSupport<ENTITY extends SimpleEntity, SAVE_
|
|||||||
* @return GlobalCrudResponse<LIST_ITEM> 返回符合条件的实体列表
|
* @return GlobalCrudResponse<LIST_ITEM> 返回符合条件的实体列表
|
||||||
* @throws Exception 查询过程中可能抛出的异常
|
* @throws Exception 查询过程中可能抛出的异常
|
||||||
*/
|
*/
|
||||||
|
@Transactional(readOnly = true)
|
||||||
@PostMapping(LIST)
|
@PostMapping(LIST)
|
||||||
@Override
|
@Override
|
||||||
public GlobalResponse<Map<String, Object>> list(@RequestBody Query query) throws Exception {
|
public GlobalResponse<Map<String, Object>> list(@RequestBody Query query) throws Exception {
|
||||||
@@ -181,6 +185,7 @@ public abstract class SimpleControllerSupport<ENTITY extends SimpleEntity, SAVE_
|
|||||||
* @return GlobalResponse<DETAIL_ITEM> 返回实体详情
|
* @return GlobalResponse<DETAIL_ITEM> 返回实体详情
|
||||||
* @throws Exception 查询过程中可能抛出的异常
|
* @throws Exception 查询过程中可能抛出的异常
|
||||||
*/
|
*/
|
||||||
|
@Transactional(readOnly = true)
|
||||||
@GetMapping(DETAIL)
|
@GetMapping(DETAIL)
|
||||||
@Override
|
@Override
|
||||||
public GlobalResponse<DETAIL_ITEM> detail(@PathVariable("id") Long id) throws Exception {
|
public GlobalResponse<DETAIL_ITEM> detail(@PathVariable("id") Long id) throws Exception {
|
||||||
@@ -195,6 +200,7 @@ public abstract class SimpleControllerSupport<ENTITY extends SimpleEntity, SAVE_
|
|||||||
* @return GlobalResponse<Object> 返回删除结果
|
* @return GlobalResponse<Object> 返回删除结果
|
||||||
* @throws Exception 删除过程中可能抛出的异常
|
* @throws Exception 删除过程中可能抛出的异常
|
||||||
*/
|
*/
|
||||||
|
@Transactional(rollbackFor = Throwable.class)
|
||||||
@GetMapping(REMOVE)
|
@GetMapping(REMOVE)
|
||||||
@Override
|
@Override
|
||||||
public GlobalResponse<Object> remove(@PathVariable("id") Long id) throws Exception {
|
public GlobalResponse<Object> remove(@PathVariable("id") Long id) throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user