feat: Spring Boot 整合 Spring Cache 和 Redis 缓存

This commit is contained in:
haoxr
2023-12-04 21:39:12 +08:00
parent 0fa99a61ae
commit e28b3e9490
12 changed files with 176 additions and 35 deletions

View File

@@ -19,6 +19,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import java.util.List;
@Tag(name = "03.角色接口")
@@ -29,7 +30,7 @@ public class SysRoleController {
private final SysRoleService roleService;
@Operation(summary = "角色分页列表" )
@Operation(summary = "角色分页列表")
@GetMapping("/page")
public PageResult<RolePageVO> getRolePage(
@ParameterObject RolePageQuery queryParams
@@ -44,7 +45,7 @@ public class SysRoleController {
List<Option> list = roleService.listRoleOptions();
return Result.success(list);
}
@Operation(summary = "新增角色")
@PostMapping
@PreAuthorize("@ss.hasPerm('sys:role:add')")
@@ -57,7 +58,7 @@ public class SysRoleController {
@Operation(summary = "角色表单数据")
@GetMapping("/{roleId}/form")
public Result<RoleForm> getRoleForm(
@Parameter(description ="角色ID") @PathVariable Long roleId
@Parameter(description = "角色ID") @PathVariable Long roleId
) {
RoleForm roleForm = roleService.getRoleForm(roleId);
return Result.success(roleForm);
@@ -75,7 +76,7 @@ public class SysRoleController {
@DeleteMapping("/{ids}")
@PreAuthorize("@ss.hasPerm('sys:role:delete')")
public Result deleteRoles(
@Parameter(description ="删除角色,多个以英文逗号(,)分割") @PathVariable String ids
@Parameter(description = "删除角色,多个以英文逗号(,)分割") @PathVariable String ids
) {
boolean result = roleService.deleteRoles(ids);
return Result.judge(result);
@@ -84,8 +85,8 @@ public class SysRoleController {
@Operation(summary = "修改角色状态")
@PutMapping(value = "/{roleId}/status")
public Result updateRoleStatus(
@Parameter(description ="角色ID") @PathVariable Long roleId,
@Parameter(description ="状态(1:启用;0:禁用)") @RequestParam Integer status
@Parameter(description = "角色ID") @PathVariable Long roleId,
@Parameter(description = "状态(1:启用;0:禁用)") @RequestParam Integer status
) {
boolean result = roleService.updateRoleStatus(roleId, status);
return Result.judge(result);
@@ -94,19 +95,19 @@ public class SysRoleController {
@Operation(summary = "获取角色的菜单ID集合")
@GetMapping("/{roleId}/menuIds")
public Result<List<Long>> getRoleMenuIds(
@Parameter(description ="角色ID") @PathVariable Long roleId
@Parameter(description = "角色ID") @PathVariable Long roleId
) {
List<Long> menuIds = roleService.getRoleMenuIds(roleId);
return Result.success(menuIds);
}
@Operation(summary = "分配菜单权限给角色")
@Operation(summary = "分配菜单(包括按钮权限)给角色")
@PutMapping("/{roleId}/menus")
public Result updateRoleMenus(
public Result assignMenusToRole(
@PathVariable Long roleId,
@RequestBody List<Long> menuIds
) {
boolean result = roleService.updateRoleMenus(roleId,menuIds);
boolean result = roleService.assignMenusToRole(roleId, menuIds);
return Result.judge(result);
}
}