mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-23 15:35:06 +08:00
增加 Spring Cache 框架
This commit is contained in:
@ -0,0 +1,19 @@
|
||||
### 请求 /infra/test-demo/get 接口 => 成功
|
||||
GET {{baseUrl}}/infra/test-demo/get?id=106
|
||||
Authorization: Bearer {{token}}
|
||||
tenant-id: {{adminTenentId}}
|
||||
|
||||
### 请求 /infra/test-demo/update 接口 => 成功
|
||||
PUT {{baseUrl}}/infra/test-demo/update
|
||||
Authorization: Bearer {{token}}
|
||||
tenant-id: {{adminTenentId}}
|
||||
Content-Type: application/json
|
||||
|
||||
|
||||
{
|
||||
"id": 106,
|
||||
"name": "测试",
|
||||
"status": "0",
|
||||
"type": 1,
|
||||
"category": 1
|
||||
}
|
@ -1,30 +1,29 @@
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.test;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.test.vo.*;
|
||||
import cn.iocoder.yudao.module.infra.convert.test.TestDemoConvert;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.test.TestDemoDO;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.annotations.*;
|
||||
|
||||
import javax.validation.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.test.vo.*;
|
||||
import cn.iocoder.yudao.module.infra.service.test.TestDemoService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
@Api(tags = "管理后台 - 字典类型")
|
||||
@RestController
|
||||
@ -37,13 +36,15 @@ public class TestDemoController {
|
||||
|
||||
@PostMapping("/create")
|
||||
@ApiOperation("创建字典类型")
|
||||
@PreAuthorize("@ss.hasPermission('infra:test-demo:create')") public CommonResult<Long> createTestDemo(@Valid @RequestBody TestDemoCreateReqVO createReqVO) {
|
||||
@PreAuthorize("@ss.hasPermission('infra:test-demo:create')")
|
||||
public CommonResult<Long> createTestDemo(@Valid @RequestBody TestDemoCreateReqVO createReqVO) {
|
||||
return success(testDemoService.createTestDemo(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@ApiOperation("更新字典类型")
|
||||
@PreAuthorize("@ss.hasPermission('infra:test-demo:update')") public CommonResult<Boolean> updateTestDemo(@Valid @RequestBody TestDemoUpdateReqVO updateReqVO) {
|
||||
@PreAuthorize("@ss.hasPermission('infra:test-demo:update')")
|
||||
public CommonResult<Boolean> updateTestDemo(@Valid @RequestBody TestDemoUpdateReqVO updateReqVO) {
|
||||
testDemoService.updateTestDemo(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
@ -8,6 +8,8 @@ import cn.iocoder.yudao.module.infra.controller.admin.test.vo.TestDemoUpdateReqV
|
||||
import cn.iocoder.yudao.module.infra.convert.test.TestDemoConvert;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.test.TestDemoDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.test.TestDemoMapper;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@ -31,6 +33,7 @@ public class TestDemoServiceImpl implements TestDemoService {
|
||||
private TestDemoMapper testDemoMapper;
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = "test", key = "#createReqVO.id")
|
||||
public Long createTestDemo(TestDemoCreateReqVO createReqVO) {
|
||||
// 插入
|
||||
TestDemoDO testDemo = TestDemoConvert.INSTANCE.convert(createReqVO);
|
||||
@ -40,6 +43,7 @@ public class TestDemoServiceImpl implements TestDemoService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = "test", key = "#updateReqVO.id")
|
||||
public void updateTestDemo(TestDemoUpdateReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
this.validateTestDemoExists(updateReqVO.getId());
|
||||
@ -49,6 +53,7 @@ public class TestDemoServiceImpl implements TestDemoService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = "test", key = "'test:' + #id")
|
||||
public void deleteTestDemo(Long id) {
|
||||
// 校验存在
|
||||
this.validateTestDemoExists(id);
|
||||
@ -63,6 +68,7 @@ public class TestDemoServiceImpl implements TestDemoService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(cacheNames = "test", key = "#id")
|
||||
public TestDemoDO getTestDemo(Long id) {
|
||||
return testDemoMapper.selectById(id);
|
||||
}
|
||||
|
Reference in New Issue
Block a user