微服务 教程
1085个小节阅读:195.9k
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
后台用户也称为管理员,每个管理员能在后台进行的操作不同,所以不同的管理员有不同的权限。在项目中,权限表的设计为用户—角色
多对多,角色—权限
多对多,既一个用户有多个角色,一个角色有多个权限。所以网站后台首先要拥有用户管理、角色管理、权限管理的功能。
后台用户服务模块提供了以上服务。
创建名为shopping_admin_service
的SpringBoot工程,添加相关依赖。
xxxxxxxxxx
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- MyBatisPlus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.0</version>
</dependency>
<!-- mysql驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.itbaizhan</groupId>
<artifactId>shopping_common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- dubbo -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.7.8</version>
</dependency>
<!-- 操作zookeeper -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
设置该工程的父工程为shopping
。
xxxxxxxxxx
<parent>
<groupId>com.itbaizhan</groupId>
<artifactId>shopping</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
给shopping
工程设置子模块
xxxxxxxxxx
<!-- 子模块 -->
<modules>
<!-- 管理员服务 -->
<module>shopping_admin_service</module>
</modules>
编写配置文件application.yml
xxxxxxxxxx
# 端口号
server
port9002
# 日志格式
logging
pattern
console'%d{HH:mm:ss.SSS} %clr(%-5level) --- [%-15thread] %cyan(%-50logger{50}):%msg%n'
#配置mybatis-plus
mybatis-plus
global-config
db-config
# 表名前缀
table-prefix bz_
# 主键生成策略为自增
id-type auto
configuration
# 关闭列名自动驼峰命名规则映射
map-underscore-to-camel-casefalse
log-impl org.apache.ibatis.logging.stdout.StdOutImpl #开启sql日志
spring
# 数据源
datasource
driver-class-name com.mysql.cj.jdbc.Driver
url jdbc mysql ///baizhanshopping?serverTimezone=UTC
username root
password root
dubbo
application
name shopping_admin_service # 项目名
registry
address zookeeper //192.168.25.100 # 注册中心地址
port 2181 # 注册中心的端口
timeout 10000 # 注册到zk上超时时间,ms
protocol
name dubbo # dubbo使用的协议
port -1 # dubbo自动分配端口
scan
base-packages com.itbaizhan.shopping_admin_service.service # 包扫描
创建管理员Mapper接口
xxxxxxxxxx
public interface AdminMapper extends BaseMapper<Admin> {
}
配置启动类扫描MyBatis-Plus
接口
xxxxxxxxxx
"com.itbaizhan.shopping_admin_service.mapper") (
public class ShoppingAdminServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ShoppingAdminServiceApplication.class, args);
}
}