Compare commits
10
Commits
a7bdcb3c17
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f770d69a8 | ||
|
|
8a7d39e533 | ||
|
|
59feaf0ccd | ||
|
|
06009637b4 | ||
|
|
4a18c64ca6 | ||
|
|
791c2fc2ee | ||
|
|
063aff963a | ||
|
|
937f040904 | ||
|
|
b66a0907d9 | ||
|
|
41aee2b3df |
@@ -0,0 +1,2 @@
|
||||
.idea
|
||||
/target
|
||||
@@ -1,3 +1,28 @@
|
||||
# permission-control
|
||||
|
||||
😃 AOP + 自定义注解 + RABC 实现操作权限鉴定
|
||||
😃 AOP + 自定义注解 + RBAC 实现操作权限鉴定
|
||||
|
||||
## 术语
|
||||
|
||||
RBAC:Role-Based Access Control 基于角色的访问控制
|
||||
|
||||
## 数据库表
|
||||
|
||||
### 访问控制
|
||||
|
||||
- 用户表
|
||||
- 用户-权限表
|
||||
- 角色表
|
||||
- 角色-权限表
|
||||
- 权限表
|
||||
|
||||
### 业务
|
||||
|
||||
- 商品列表
|
||||
|
||||
## 规则
|
||||
|
||||
角色:USER / ADMIN
|
||||
|
||||
- `USER`: 能够获取商品信息
|
||||
- `ADMIN`: 能够对商品信息进行增删改
|
||||
@@ -0,0 +1,76 @@
|
||||
-- init.sql
|
||||
-- 用户表
|
||||
CREATE TABLE users (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT COMMENT "用户id",
|
||||
username VARCHAR(50) UNIQUE NOT NULL COMMENT "用户名",
|
||||
password VARCHAR(255) NOT NULL COMMENT "密码",
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT "创建时间",
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT "更新时间"
|
||||
);
|
||||
|
||||
-- 角色表
|
||||
CREATE TABLE roles (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT COMMENT "角色id",
|
||||
name VARCHAR(50) UNIQUE NOT NULL COMMENT "角色名称",
|
||||
description TEXT COMMENT "角色描述"
|
||||
);
|
||||
|
||||
-- 权限表
|
||||
CREATE TABLE permissions (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT COMMENT "权限id",
|
||||
name VARCHAR(100) UNIQUE NOT NULL COMMENT "权限名称",
|
||||
description TEXT COMMENT "权限描述"
|
||||
);
|
||||
|
||||
-- 用户-角色关联表
|
||||
CREATE TABLE user_roles (
|
||||
user_id INT COMMENT "用户id",
|
||||
role_id INT COMMENT "角色id",
|
||||
PRIMARY KEY (user_id, role_id),
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (role_id) REFERENCES roles(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- 角色-权限关联表
|
||||
CREATE TABLE role_permissions (
|
||||
role_id INT COMMENT "角色id",
|
||||
permission_id INT COMMENT "权限id",
|
||||
PRIMARY KEY (role_id, permission_id),
|
||||
FOREIGN KEY (role_id) REFERENCES roles(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (permission_id) REFERENCES permissions(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- 商品表
|
||||
CREATE TABLE products (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT COMMENT "商品id",
|
||||
name VARCHAR(255) NOT NULL COMMENT "商品名称",
|
||||
description TEXT COMMENT "商品描述",
|
||||
price DECIMAL(10, 2) NOT NULL COMMENT "商品价格",
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT "创建时间",
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT "更新时间"
|
||||
);
|
||||
|
||||
-- 插入默认角色
|
||||
INSERT INTO roles (name, description) VALUES
|
||||
('USER', '普通用户'),
|
||||
('ADMIN', '管理员');
|
||||
|
||||
-- 插入默认权限
|
||||
INSERT INTO permissions (name, description) VALUES
|
||||
('PRODUCT_READ', '读取商品信息'),
|
||||
('PRODUCT_CREATE', '创建商品'),
|
||||
('PRODUCT_UPDATE', '更新商品'),
|
||||
('PRODUCT_DELETE', '删除商品');
|
||||
|
||||
-- 给 ADMIN 角色分配所有权限
|
||||
INSERT INTO role_permissions (role_id, permission_id)
|
||||
SELECT r.id, p.id
|
||||
FROM roles r, permissions p
|
||||
WHERE r.name = 'ADMIN';
|
||||
|
||||
|
||||
-- 给 USER 角色分配读取权限
|
||||
INSERT INTO role_permissions (role_id, permission_id)
|
||||
SELECT r.id, p.id
|
||||
FROM roles r, permissions p
|
||||
WHERE r.name = 'USER' and p.name = 'PRODUCT_READ'
|
||||
@@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
||||
http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.2.2</version>
|
||||
</parent>
|
||||
|
||||
<groupId>cn.hezhaohui.pc</groupId>
|
||||
<artifactId>permission-control</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Permission Control</name>
|
||||
<description>AOP-based permission control system with custom annotations and RBAC</description>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- spring web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- mysql -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.30</version>
|
||||
</dependency>
|
||||
|
||||
<!-- mybatis-plus -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||
<version>3.5.14</version>
|
||||
</dependency>
|
||||
|
||||
<!-- lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
||||
<version>4.4.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
package cn.hezhaohui.pc;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
@MapperScan("cn.hezhaohui.pc.mapper")
|
||||
public class Application {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.hezhaohui.pc.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 自定义注解,实现鉴权
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface PreAuthorize {
|
||||
/**
|
||||
* 权限标识符
|
||||
*/
|
||||
public String value() default "";
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package cn.hezhaohui.pc.aspect;
|
||||
|
||||
import cn.hezhaohui.pc.annotation.PreAuthorize;
|
||||
import cn.hezhaohui.pc.mapper.UserPermissionMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.Signature;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.hezhaohui.pc.service.UserService.loginUser;
|
||||
|
||||
@Component
|
||||
@Aspect
|
||||
public class AuthorizeAspect {
|
||||
|
||||
@Resource
|
||||
private UserPermissionMapper userPermissionMapper;
|
||||
|
||||
@Pointcut("@annotation(cn.hezhaohui.pc.annotation.PreAuthorize)")
|
||||
public void authorizePointCut() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 对后端接口鉴权
|
||||
* 1. 获取当前用户角色
|
||||
* 2. 获取角色对应权限
|
||||
* 3. 判断当前权限标识符是否被包含
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Around("authorizePointCut()")
|
||||
public Object handle(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
List<String> permissions = userPermissionMapper.selectPermissionByUserId(loginUser.get().getId());
|
||||
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
Method method = signature.getMethod();
|
||||
String permission = method.getAnnotation(PreAuthorize.class).value();
|
||||
|
||||
if (permissions.contains(permission)) {
|
||||
return joinPoint.proceed();
|
||||
} else {
|
||||
throw new RuntimeException("权限不足");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package cn.hezhaohui.pc.controller;
|
||||
|
||||
import cn.hezhaohui.pc.annotation.PreAuthorize;
|
||||
import cn.hezhaohui.pc.entity.Product;
|
||||
import cn.hezhaohui.pc.service.ProductService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/product")
|
||||
@Tag(name = "商品")
|
||||
public class ProductController {
|
||||
|
||||
@Resource
|
||||
private ProductService productService;
|
||||
|
||||
@GetMapping
|
||||
@Operation(summary = "列出所有商品")
|
||||
@PreAuthorize("PRODUCT_READ")
|
||||
public List<Product> listAll() {
|
||||
return productService.listAll();
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@Operation(summary = "通过id查找商品")
|
||||
@PreAuthorize("PRODUCT_READ")
|
||||
public Product findById(@PathVariable Long id) {
|
||||
return productService.getById(id);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "添加商品")
|
||||
@PreAuthorize("PRODUCT_CREATE")
|
||||
public void add(@RequestBody Product product) {
|
||||
productService.saveProduct(product);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Operation(summary = "更新商品")
|
||||
@PreAuthorize("PRODUCT_UPDATE")
|
||||
public void update(@RequestBody Product product) {
|
||||
productService.updateProduct(product);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@Operation(summary = "删除商品")
|
||||
@PreAuthorize("PRODUCT_DELETE")
|
||||
public void delete(@PathVariable Long id) {
|
||||
productService.deleteProduct(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package cn.hezhaohui.pc.controller;
|
||||
|
||||
import cn.hezhaohui.pc.entity.User;
|
||||
import cn.hezhaohui.pc.service.UserService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/users")
|
||||
@Tag(name = "用户")
|
||||
public class UserController {
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@PostMapping("/login")
|
||||
@Operation(summary = "用户登录")
|
||||
public String login(@RequestBody User user) {
|
||||
return userService.login(user);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@Operation(summary = "列出所有用户")
|
||||
public List<User> listAll() {
|
||||
return userService.listAll();
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@Operation(summary = "通过id查找用户")
|
||||
public User getById(@PathVariable Long id) {
|
||||
return userService.getById(id);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "创建用户")
|
||||
public void saveUser(@RequestBody User user) {
|
||||
userService.saveUser(user);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Operation(summary = "更新用户")
|
||||
public void updateUser(@RequestBody User user) {
|
||||
userService.updateUser(user);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public void deleteUser(@PathVariable Long id) {
|
||||
userService.deleteUser(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.hezhaohui.pc.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@TableName("products")
|
||||
public class Product {
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
private Double price;
|
||||
private LocalDateTime createdAt;
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package cn.hezhaohui.pc.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@TableName("users")
|
||||
public class User {
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
private String username;
|
||||
private String password;
|
||||
private LocalDateTime createdAt;
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package cn.hezhaohui.pc.mapper;
|
||||
|
||||
import cn.hezhaohui.pc.entity.Product;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface ProductMapper extends BaseMapper<Product> {
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package cn.hezhaohui.pc.mapper;
|
||||
|
||||
import cn.hezhaohui.pc.entity.User;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface UserMapper extends BaseMapper<User> {
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package cn.hezhaohui.pc.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface UserPermissionMapper {
|
||||
public List<String> selectPermissionByUserId(Long userId);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.hezhaohui.pc.service;
|
||||
|
||||
|
||||
|
||||
import cn.hezhaohui.pc.entity.Product;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ProductService {
|
||||
List<Product> listAll();
|
||||
Product getById(Long id);
|
||||
void saveProduct(Product Product);
|
||||
void updateProduct(Product Product);
|
||||
void deleteProduct(Long id);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.hezhaohui.pc.service;
|
||||
|
||||
import cn.hezhaohui.pc.entity.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserService {
|
||||
|
||||
ThreadLocal<User> loginUser = new ThreadLocal<>();
|
||||
|
||||
List<User> listAll();
|
||||
User getById(Long id);
|
||||
void saveUser(User user);
|
||||
void updateUser(User user);
|
||||
void deleteUser(Long id);
|
||||
|
||||
String login(User user);
|
||||
String logout();
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package cn.hezhaohui.pc.service.impl;
|
||||
|
||||
import cn.hezhaohui.pc.entity.Product;
|
||||
import cn.hezhaohui.pc.mapper.ProductMapper;
|
||||
import cn.hezhaohui.pc.service.ProductService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ProductServiceImpl implements ProductService {
|
||||
|
||||
@Resource
|
||||
private ProductMapper productMapper;
|
||||
|
||||
@Override
|
||||
public List<Product> listAll() {
|
||||
return productMapper.selectList(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Product getById(Long id) {
|
||||
return productMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveProduct(Product Product) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
Product.setCreatedAt(now);
|
||||
Product.setUpdatedAt(now);
|
||||
productMapper.insert(Product);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProduct(Product Product) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
Product.setUpdatedAt(now);
|
||||
productMapper.updateById(Product);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteProduct(Long id) {
|
||||
productMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package cn.hezhaohui.pc.service.impl;
|
||||
|
||||
import cn.hezhaohui.pc.entity.User;
|
||||
import cn.hezhaohui.pc.mapper.UserMapper;
|
||||
import cn.hezhaohui.pc.service.UserService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
ThreadLocal<User> loginUser = new ThreadLocal<>();
|
||||
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public List<User> listAll() {
|
||||
return userMapper.selectList(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getById(Long id) {
|
||||
return userMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveUser(User user) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
user.setCreatedAt(now);
|
||||
user.setUpdatedAt(now);
|
||||
userMapper.insert(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUser(User user) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
user.setUpdatedAt(now);
|
||||
userMapper.updateById(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUser(Long id) {
|
||||
userMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String login(User user) {
|
||||
User result = userMapper.selectOne(new QueryWrapper<User>().eq("username", user.getUsername()));
|
||||
loginUser.set(result);
|
||||
return "Hello, " + result.getUsername() + "!";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String logout() {
|
||||
loginUser.remove();
|
||||
return "Good bye!";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
username: root
|
||||
password: dn293830
|
||||
url: jdbc:mysql://47.121.181.112:3306/pc
|
||||
|
||||
|
||||
# springdoc-openapi项目配置
|
||||
springdoc:
|
||||
swagger-ui:
|
||||
path: /swagger-ui.html
|
||||
tags-sorter: alpha
|
||||
operations-sorter: alpha
|
||||
api-docs:
|
||||
path: /v3/api-docs
|
||||
group-configs:
|
||||
- group: 'default'
|
||||
paths-to-match: '/**'
|
||||
packages-to-scan: cn.hezhaohui.pc.controller
|
||||
# knife4j的增强配置,不需要增强可以不配
|
||||
knife4j:
|
||||
enable: true
|
||||
setting:
|
||||
language: zh_cn
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.hezhaohui.pc.mapper.UserPermissionMapper">
|
||||
|
||||
|
||||
<select id="selectPermissionByUserId" parameterType="Long" resultType="java.lang.String">
|
||||
select distinct p.name
|
||||
from permissions p
|
||||
left join role_permissions rp on p.id = rp.permission_id
|
||||
left join user_roles ur on rp.role_id = ur.role_id
|
||||
where ur.user_id = #{userId}
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user