├── .gitignore
├── .mvn
└── wrapper
│ ├── MavenWrapperDownloader.java
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── README.md
├── doubao.sql
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
├── main
├── java
│ └── com
│ │ └── douyuehan
│ │ └── doubao
│ │ ├── DoubaoApplication.java
│ │ ├── common
│ │ ├── api
│ │ │ ├── ApiErrorCode.java
│ │ │ ├── ApiResult.java
│ │ │ └── IErrorCode.java
│ │ ├── exception
│ │ │ ├── ApiAsserts.java
│ │ │ ├── ApiException.java
│ │ │ └── GlobalExceptionHandler.java
│ │ └── mybatisplus
│ │ │ └── MybatisPlusConfig.java
│ │ ├── config
│ │ └── GlobalWebMvcConfigurer.java
│ │ ├── controller
│ │ ├── BaseController.java
│ │ ├── BmsBillboardController.java
│ │ ├── BmsCommentController.java
│ │ ├── BmsPostController.java
│ │ ├── BmsPromotionController.java
│ │ ├── BmsRelationshipController.java
│ │ ├── BmsSearchController.java
│ │ ├── BmsTagController.java
│ │ ├── BmsTipController.java
│ │ └── UmsUserController.java
│ │ ├── jwt
│ │ ├── JwtAuthenticationFilter.java
│ │ └── JwtUtil.java
│ │ ├── mapper
│ │ ├── BmsBillboardMapper.java
│ │ ├── BmsCommentMapper.java
│ │ ├── BmsFollowMapper.java
│ │ ├── BmsPromotionMapper.java
│ │ ├── BmsTagMapper.java
│ │ ├── BmsTipMapper.java
│ │ ├── BmsTopicMapper.java
│ │ ├── BmsTopicTagMapper.java
│ │ └── UmsUserMapper.java
│ │ ├── model
│ │ ├── dto
│ │ │ ├── CommentDTO.java
│ │ │ ├── CreateTopicDTO.java
│ │ │ ├── LoginDTO.java
│ │ │ └── RegisterDTO.java
│ │ ├── entity
│ │ │ ├── BmsBillboard.java
│ │ │ ├── BmsComment.java
│ │ │ ├── BmsFollow.java
│ │ │ ├── BmsPost.java
│ │ │ ├── BmsPromotion.java
│ │ │ ├── BmsTag.java
│ │ │ ├── BmsTip.java
│ │ │ ├── BmsTopicTag.java
│ │ │ └── UmsUser.java
│ │ └── vo
│ │ │ ├── CommentVO.java
│ │ │ ├── PostVO.java
│ │ │ └── ProfileVO.java
│ │ ├── service
│ │ ├── IBmsBillboardService.java
│ │ ├── IBmsCommentService.java
│ │ ├── IBmsFollowService.java
│ │ ├── IBmsPostService.java
│ │ ├── IBmsPromotionService.java
│ │ ├── IBmsTagService.java
│ │ ├── IBmsTipService.java
│ │ ├── IBmsTopicTagService.java
│ │ ├── IUmsUserService.java
│ │ └── impl
│ │ │ ├── IBmsBillboardServiceImpl.java
│ │ │ ├── IBmsCommentServiceImpl.java
│ │ │ ├── IBmsFollowServiceImpl.java
│ │ │ ├── IBmsPostServiceImpl.java
│ │ │ ├── IBmsPromotionServiceImpl.java
│ │ │ ├── IBmsTagServiceImpl.java
│ │ │ ├── IBmsTipServiceImpl.java
│ │ │ ├── IBmsTopicTagServiceImpl.java
│ │ │ └── IUmsUserServiceImpl.java
│ │ └── utils
│ │ └── MD5Utils.java
└── resources
│ ├── application-dev.yaml
│ ├── application-prod.yaml
│ ├── application.yaml
│ └── mapper
│ ├── BmsCommentMapper.xml
│ ├── BmsPostMapper.xml
│ ├── BmsPostTagMapper.xml
│ └── BmsTipMapper.xml
└── test
└── java
└── com
└── douyuehan
└── doubao
└── DoubaoApplicationTests.java
/.gitignore:
--------------------------------------------------------------------------------
1 | HELP.md
2 | target/
3 | !.mvn/wrapper/maven-wrapper.jar
4 | !**/src/main/**/target/
5 | !**/src/test/**/target/
6 |
7 | ### STS ###
8 | .apt_generated
9 | .classpath
10 | .factorypath
11 | .project
12 | .settings
13 | .springBeans
14 | .sts4-cache
15 |
16 | ### IntelliJ IDEA ###
17 | .idea
18 | *.iws
19 | *.iml
20 | *.ipr
21 |
22 | ### NetBeans ###
23 | /nbproject/private/
24 | /nbbuild/
25 | /dist/
26 | /nbdist/
27 | /.nb-gradle/
28 | build/
29 | !**/src/main/**/build/
30 | !**/src/test/**/build/
31 |
32 | ### VS Code ###
33 | .vscode/
34 |
--------------------------------------------------------------------------------
/.mvn/wrapper/MavenWrapperDownloader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007-present the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | import java.net.*;
18 | import java.io.*;
19 | import java.nio.channels.*;
20 | import java.util.Properties;
21 |
22 | public class MavenWrapperDownloader {
23 |
24 | private static final String WRAPPER_VERSION = "0.5.6";
25 | /**
26 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
27 | */
28 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
29 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
30 |
31 | /**
32 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
33 | * use instead of the default one.
34 | */
35 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
36 | ".mvn/wrapper/maven-wrapper.properties";
37 |
38 | /**
39 | * Path where the maven-wrapper.jar will be saved to.
40 | */
41 | private static final String MAVEN_WRAPPER_JAR_PATH =
42 | ".mvn/wrapper/maven-wrapper.jar";
43 |
44 | /**
45 | * Name of the property which should be used to override the default download url for the wrapper.
46 | */
47 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
48 |
49 | public static void main(String args[]) {
50 | System.out.println("- Downloader started");
51 | File baseDirectory = new File(args[0]);
52 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
53 |
54 | // If the maven-wrapper.properties exists, read it and check if it contains a custom
55 | // wrapperUrl parameter.
56 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
57 | String url = DEFAULT_DOWNLOAD_URL;
58 | if (mavenWrapperPropertyFile.exists()) {
59 | FileInputStream mavenWrapperPropertyFileInputStream = null;
60 | try {
61 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
62 | Properties mavenWrapperProperties = new Properties();
63 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
64 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
65 | } catch (IOException e) {
66 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
67 | } finally {
68 | try {
69 | if (mavenWrapperPropertyFileInputStream != null) {
70 | mavenWrapperPropertyFileInputStream.close();
71 | }
72 | } catch (IOException e) {
73 | // Ignore ...
74 | }
75 | }
76 | }
77 | System.out.println("- Downloading from: " + url);
78 |
79 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
80 | if (!outputFile.getParentFile().exists()) {
81 | if (!outputFile.getParentFile().mkdirs()) {
82 | System.out.println(
83 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
84 | }
85 | }
86 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
87 | try {
88 | downloadFileFromURL(url, outputFile);
89 | System.out.println("Done");
90 | System.exit(0);
91 | } catch (Throwable e) {
92 | System.out.println("- Error downloading");
93 | e.printStackTrace();
94 | System.exit(1);
95 | }
96 | }
97 |
98 | private static void downloadFileFromURL(String urlString, File destination) throws Exception {
99 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
100 | String username = System.getenv("MVNW_USERNAME");
101 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
102 | Authenticator.setDefault(new Authenticator() {
103 | @Override
104 | protected PasswordAuthentication getPasswordAuthentication() {
105 | return new PasswordAuthentication(username, password);
106 | }
107 | });
108 | }
109 | URL website = new URL(urlString);
110 | ReadableByteChannel rbc;
111 | rbc = Channels.newChannel(website.openStream());
112 | FileOutputStream fos = new FileOutputStream(destination);
113 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
114 | fos.close();
115 | rbc.close();
116 | }
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/songboriceman/doubao_community_backend/896ec3669aa1d8d57014a8ab44623f5f88570b7f/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
3 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### 豆宝社区项目实战视频教程简介
2 | 本项目实战视频教程全部免费,配套代码完全开源。手把手从零开始搭建一个目前应用最广泛的Springboot+Vue前后端分离多用户社区项目。本项目难度适中,为便于大家学习,每一集视频教程对应在Github上的每一次提交。
3 |
4 | ### 致谢
5 | 本项目大量借鉴了[极光社区项目](https://github.com/haoyu21/aurora),在此感谢原作者的无私开源。本项目在其基础上做了一些增删,删除了一些未完成的模块(活动,旅游),新增了评论功能,简化了后端认证与授权功能。最主要的工作是将原项目从零开始开始搭建,各个功能的实现分解成几十步来完成,便于大家更好的学习。
6 |
7 | ### 在线体验
8 |
9 | http://kamiba.gitee.io/doubao_deploy_frontend
10 |
11 | ### 代码开源地址
12 | [前端](https://github.com/songboriceman/doubao_community_frontend)
13 | [后端](https://github.com/songboriceman/doubao_community_backend)
14 |
15 | ### 视频教程地址
16 | [视频教程](https://www.bilibili.com/video/BV1Wz4y1U7vC)
17 |
18 | ### 项目主要业务及实现的功能
19 | 本项目类似一个简版的掘金这样的技术社区,实现了多个用户注册,登录,发帖,回帖,评论,关注,用户中心等功能。
20 |
21 | ### 前端技术栈
22 | Vue
23 |
24 | Vuex
25 |
26 | Vue Router
27 |
28 | Axios
29 |
30 | Bulma
31 |
32 | Buefy
33 |
34 | Element
35 |
36 | Vditor
37 |
38 | DarkReader
39 |
40 | ### 后端技术栈
41 | Spring Boot
42 |
43 | Mysql
44 |
45 | Mybatis
46 |
47 | MyBatis-Plus
48 |
49 | Spring Security
50 |
51 | JWT
52 |
53 | Lombok
54 |
55 | ### 项目实战大纲:
56 | 01.豆宝社区项目介绍
57 |
58 | 02.豆宝社区项目所需的基础知识
59 |
60 | 03.前端项目搭建
61 |
62 | 04.前端公告板功能实现
63 |
64 | 05.初始化springboot后端项目
65 |
66 | 06.初始化后端数据库,springboot配置mybatis连接
67 |
68 | 07.后端项目目录结构初始化
69 |
70 | 08.后端公告板接口功能实现01
71 |
72 | 09.后端公告板接口功能实现02
73 |
74 | 10.前端端公告板接口功能实现
75 |
76 | 11.实现跨域,前后端接口联调
77 |
78 | 12.每日一句功能前端界面实现01
79 |
80 | 13.每日一句功能前端界面实现02
81 |
82 | 14.每日一句功能前端接口实现
83 |
84 | 15.每日一句功能后端接口实现
85 |
86 | 16.(非常重要)善用github提交记录进行项目学习
87 |
88 | 17.推广链接功能 前后端实现
89 |
90 | 18.用户注册前端实现
91 |
92 | 19.用户注册后端实现
93 |
94 | 20.jwt以及web通信流程
95 |
96 | 21.用户登录后端实现
97 |
98 | 22.vuex简介
99 |
100 | 23.js-cookie介绍
101 |
102 | 24.用户登录前端实现
103 |
104 | 25.前端侧边栏,马上入驻,社区登入功能
105 |
106 | 26.前端在axios请求拦截器中在请求头中加入jwt
107 |
108 | 27.后端设置请求拦截器检查用户请求头中是否包含jwt01
109 |
110 | 28.后端设置请求拦截器检查用户请求头中是否包含jwt02
111 |
112 | 29.前端header实现01
113 |
114 | 30.前端header实现02
115 |
116 | 31.退出登录
117 |
118 | 32.前端页脚功能实现
119 |
120 | 33.帖子列表功能前端
121 |
122 | 34.帖子列表功能后端
123 |
124 | 35.帖子分页功能实现
125 |
126 | 36.前端实现发表帖子功能
127 |
128 | 37.后端实现发表帖子功能
129 |
130 | 38.前端实现帖子详情功能
131 |
132 | 39.后端实现帖子详情功能
133 |
134 | 40.帖子详情右侧边栏帖子作者详情功能实现(前端)
135 |
136 | 41.帖子详情右侧边栏帖子作者详情用户关注功能实现(后端)
137 |
138 | 42.随便看看模块前端实现
139 |
140 | 43.随便看看模块后端实现
141 |
142 | 44.评论列表功能前端实现
143 |
144 | 45.评论列表功能后端实现
145 |
146 | 46.添加评论功能前端实现
147 |
148 | 47.添加评论功能后端实现
149 |
150 | 48.帖子更新与删除功能前后端实现
151 |
152 | 49.显示某个标签的全部文章功能前端
153 |
154 | 50.显示某个标签的全部文章功能后端实现
155 |
156 | 51.帖子搜索功能前端实现
157 |
158 | 52.帖子搜索功能前端实现
159 |
160 | 53.用户中心功能前端实现
161 |
162 | 54.用户中心功能前端实现
163 |
164 | 55.用户个人信息修改
165 |
166 | 56.前端发帖,留言等页面登录权限验证
167 |
168 | 57.后端发帖,留言等需要登录页面的权限验证
169 |
170 | 58.项目总结及遗留问题说明
171 |
172 | 59.(重要的说明)如何利用github上开源的项目代码提交记录更有效的学习本项目
173 |
174 | ### 豆约翰团队:
175 | 一群热爱分享技术,拥有多年开发经验及培训经验的老司机组成
176 |
177 | ### 擅长的领域:
178 | java,python,前端,c++,.net
179 |
180 | ### 项目部分截图
181 | #### PC
182 | #### 首页
183 | 
184 | #### 发表文章
185 | 
186 |
187 | #### 文章详情及评论页面
188 | 
189 |
190 | #### 个人中心
191 | 
192 | #### 用户设置
193 | 
194 | #### 移动端
195 | #### 首页
196 | 
197 | #### 用户中心
198 | 
199 | #### 详情页
200 | 
201 |
202 | ### 技术讨论群
203 |
204 | 为方便同学们讨论项目中的技术,建了一个QQ群:
205 |
206 | 
207 |
208 |
209 |
210 |
--------------------------------------------------------------------------------
/doubao.sql:
--------------------------------------------------------------------------------
1 | /*
2 | Navicat Premium Data Transfer
3 |
4 | Source Server : localhost
5 | Source Server Type : MySQL
6 | Source Server Version : 80022
7 | Source Host : localhost:3306
8 | Source Schema : doubao
9 |
10 | Target Server Type : MySQL
11 | Target Server Version : 80022
12 | File Encoding : 65001
13 | */
14 |
15 | SET NAMES utf8mb4;
16 | SET FOREIGN_KEY_CHECKS = 0;
17 |
18 | -- ----------------------------
19 | -- Table structure for bms_billboard
20 | -- ----------------------------
21 | DROP TABLE IF EXISTS `bms_billboard`;
22 | CREATE TABLE `bms_billboard` (
23 | `id` int NOT NULL AUTO_INCREMENT COMMENT '主键',
24 | `content` varchar(255) CHARACTER SET utf8mb4 NOT NULL COMMENT '公告',
25 | `create_time` datetime NULL DEFAULT NULL COMMENT '公告时间',
26 | `show` tinyint(1) NULL DEFAULT NULL COMMENT '1:展示中,0:过期',
27 | PRIMARY KEY (`id`) USING BTREE
28 | ) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8mb4 COMMENT = '全站公告' ROW_FORMAT = DYNAMIC;
29 |
30 | -- ----------------------------
31 | -- Records of bms_billboard
32 | -- ----------------------------
33 | INSERT INTO `bms_billboard` VALUES (2, 'R1.0 开始已实现护眼模式 ,妈妈再也不用担心我的眼睛了。', '2020-11-19 17:16:19', 0);
34 | INSERT INTO `bms_billboard` VALUES (4, '系统已更新至最新版1.0.1', NULL, 1);
35 |
36 |
37 | -- ----------------------------
38 | -- Table structure for bms_follow
39 | -- ----------------------------
40 | DROP TABLE IF EXISTS `bms_follow`;
41 | CREATE TABLE `bms_follow` (
42 | `id` int NOT NULL AUTO_INCREMENT COMMENT '主键',
43 | `parent_id` varchar(20) CHARACTER SET utf8mb4 NULL DEFAULT NULL COMMENT '被关注人ID',
44 | `follower_id` varchar(20) CHARACTER SET utf8mb4 NULL DEFAULT NULL COMMENT '关注人ID',
45 | PRIMARY KEY (`id`) USING BTREE
46 | ) ENGINE = InnoDB AUTO_INCREMENT = 130 CHARACTER SET = utf8mb4 COMMENT = '用户关注' ROW_FORMAT = DYNAMIC;
47 |
48 | -- ----------------------------
49 | -- Records of bms_follow
50 | -- ----------------------------
51 | INSERT INTO `bms_follow` VALUES (65, '1329723594994229250', '1317498859501797378');
52 | INSERT INTO `bms_follow` VALUES (85, '1332912847614083073', '1332636310897664002');
53 | INSERT INTO `bms_follow` VALUES (129, '1349290158897311745', '1349618748226658305');
54 |
55 | -- ----------------------------
56 | -- Table structure for bms_post
57 | -- ----------------------------
58 | DROP TABLE IF EXISTS `bms_post`;
59 | CREATE TABLE `bms_post` (
60 | `id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '主键',
61 | `title` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '标题',
62 | `content` longtext CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT 'markdown内容',
63 | `user_id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '作者ID',
64 | `comments` int NOT NULL DEFAULT 0 COMMENT '评论统计',
65 | `collects` int NOT NULL DEFAULT 0 COMMENT '收藏统计',
66 | `view` int NOT NULL DEFAULT 0 COMMENT '浏览统计',
67 | `top` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否置顶,1-是,0-否',
68 | `essence` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否加精,1-是,0-否',
69 | `section_id` int NULL DEFAULT 0 COMMENT '专栏ID',
70 | `create_time` datetime NOT NULL COMMENT '发布时间',
71 | `modify_time` datetime NULL DEFAULT NULL COMMENT '修改时间',
72 | UNIQUE INDEX `title`(`title`) USING BTREE,
73 | INDEX `user_id`(`user_id`) USING BTREE,
74 | INDEX `create_time`(`create_time`) USING BTREE
75 | ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '话题表' ROW_FORMAT = DYNAMIC;
76 |
77 | -- ----------------------------
78 | -- Records of bms_post
79 | -- ----------------------------
80 | INSERT INTO `bms_post` VALUES ('1333447953558765569', '1', '12\n2\n\n', '1349290158897311745', 0, 0, 77, b'0', b'0', 0, '2020-12-01 00:29:01', '2020-12-03 23:56:51');
81 | INSERT INTO `bms_post` VALUES ('1349362401438392322', '2021 健康,快乐', '2021的`FLAG`\n\n1. 技能进步\n2. 没有烦恼\n3. 发财 :smile:\n\n', '1349290158897311745', 0, 0, 21, b'0', b'0', 0, '2021-01-13 22:27:21', '2021-01-14 17:30:13');
82 | INSERT INTO `bms_post` VALUES ('1334481725322297346', 'hello,spring-security', ':hibiscus: spring-security\n\n', '1349290158897311745', 0, 0, 46, b'0', b'0', 0, '2020-12-03 20:56:51', NULL);
83 | INSERT INTO `bms_post` VALUES ('1332650453142827009', '哈哈哈,helloworld', '这是第一篇哦\n\n> hi :handshake: 你好\n\n`hello world`\n\n:+1: 很好\n', '1349290158897311745', 0, 0, 29, b'0', b'0', 1, '2020-11-28 19:40:02', '2020-11-28 19:46:39');
84 | INSERT INTO `bms_post` VALUES ('1333432347031646209', '哈哈哈,换了个dark主题', '主题更换为Dark\n\n', '1349290158897311745', 0, 0, 6, b'0', b'0', 0, '2020-11-30 23:27:00', NULL);
85 | INSERT INTO `bms_post` VALUES ('1333668258587750401', '嘿嘿,测试一下啊', '大家好\n`Hello everyone!`\n\n\n\n', '1349290158897311745', 0, 0, 7, b'0', b'0', 0, '2020-12-01 15:04:26', '2020-12-01 16:49:14');
86 | INSERT INTO `bms_post` VALUES ('1332682473151635458', '我要发财', '2021 冲冲冲!!!\n\n', '1349290158897311745', 0, 0, 94, b'0', b'0', 2, '2020-11-28 21:47:16', '2020-11-30 19:40:22');
87 | INSERT INTO `bms_post` VALUES ('1333695976536748034', '最新版本介绍,同步更新!', '
一款基于SpringBoot构建的智慧社区系统
\n\n\n
\n
\n
\n\n### Hi there :wave:\n\n\n\n[](https://github.com/1020317774)\n\n[](https://github.com/1020317774)\n---------\n\n> 作者:王一晨\n> github:[https://github.com/1020317774](https://github.com/1020317774)\n\n## 技术栈\n\n- [x] SpringBoot 2.X\n- [x] Mysql 8.X\n- [x] Mybatis\n- [x] MybatisPlus\n- [x] Redis\n- [x] Jwt\n- [x] FastJson\n- [x] Hutool\n- [x] Lombok\n- [ ] ElasticSearch\n\n……\n\n## 安装指导\n\n- 克隆\n\n```java\ngit clone https://github.com/1020317774/rhapsody-admin.git\n```\n\n- 修改`application.properties`选择环境\n- 修改多环境配置中的redis参数和数据库\n- 启动`BootApplication`\n- 访问[`http://127.0.0.1:10000`](http://127.0.0.1:10000)\n\n', '1349290158897311745', 0, 0, 45, b'1', b'1', 0, '2020-12-01 16:54:34', '2020-12-01 17:05:00');
88 | INSERT INTO `bms_post` VALUES ('1349631541260595202', '权限部分 OK', '1. 创建 ok\n2. 修改 ok\n3. 删除 ok\n\n', '1349290158897311745', 0, 0, 17, b'0', b'0', 0, '2021-01-14 16:16:49', '2021-01-14 16:18:53');
89 | INSERT INTO `bms_post` VALUES ('1333676096156528641', '测试', '测试\n\n', '1349290158897311745', 0, 0, 38, b'0', b'0', 0, '2020-12-01 15:35:34', NULL);
90 | INSERT INTO `bms_post` VALUES ('1332681213400817665', '聚合查询并统计', '* [x] SQL:\n\n```sql\nSELECT s.*,\nCOUNT(t.id) AS topics\nFROM section s\nLEFT JOIN topic t\nON s.id = t.section_id\nGROUP BY s.title\n```\n\n', '1349290158897311745', 0, 0, 55, b'0', b'0', 1, '2020-11-28 21:42:16', '2020-11-29 15:00:42');
91 | INSERT INTO `bms_post` VALUES ('1335149981733449729', '视频嵌入', ':+1:\n\n[https://www.bilibili.com/video/BV1w64y1f7w3](https://www.bilibili.com/video/BV1w64y1f7w3)\n\n[1](https://www.bilibili.com/video/BV1tp4y1x72w)\n\n```\n.vditor-reset pre > code\n```\n\n```\npublic class HelloWorld {\n\npublic static void main(String[] args) {\n System.out.println(\"Hello World!\");\n}\n}\n```\n\n', '1349290158897311745', 0, 0, 41, b'0', b'0', 0, '2020-12-05 17:12:16', '2021-01-14 13:06:16');
92 |
93 |
94 | -- ----------------------------
95 | -- Table structure for bms_comment
96 | -- ----------------------------
97 | DROP TABLE IF EXISTS `bms_comment`;
98 | CREATE TABLE `bms_comment` (
99 | `id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '主键',
100 | `content` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '内容',
101 | `user_id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '作者ID',
102 | `topic_id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'topic_id',
103 | `create_time` datetime NOT NULL COMMENT '发布时间',
104 | `modify_time` datetime NULL DEFAULT NULL COMMENT '修改时间',
105 | PRIMARY KEY (`id`) USING BTREE
106 | ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '评论表' ROW_FORMAT = DYNAMIC;
107 |
108 | -- ----------------------------
109 | -- Table structure for bms_tag
110 | -- ----------------------------
111 | DROP TABLE IF EXISTS `bms_tag`;
112 | CREATE TABLE `bms_tag` (
113 | `id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '标签ID',
114 | `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '标签',
115 | `topic_count` int NOT NULL DEFAULT 0 COMMENT '关联话题',
116 | PRIMARY KEY (`id`) USING BTREE,
117 | UNIQUE INDEX `name`(`name`) USING BTREE
118 | ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '标签表' ROW_FORMAT = DYNAMIC;
119 |
120 | -- ----------------------------
121 | -- Records of bms_tag
122 | -- ----------------------------
123 | INSERT INTO `bms_tag` VALUES ('1332650453377708034', 'java', 1);
124 | INSERT INTO `bms_tag` VALUES ('1332681213568589825', 'css', 1);
125 | INSERT INTO `bms_tag` VALUES ('1332681213631504385', 'mongodb', 1);
126 | INSERT INTO `bms_tag` VALUES ('1332682473218744321', 'python', 1);
127 | INSERT INTO `bms_tag` VALUES ('1332913064463794178', 'vue', 2);
128 | INSERT INTO `bms_tag` VALUES ('1332913064530903041', 'react', 1);
129 | INSERT INTO `bms_tag` VALUES ('1333432347107143681', 'node', 1);
130 | INSERT INTO `bms_tag` VALUES ('1333432347107143682', 'mysql', 1);
131 | INSERT INTO `bms_tag` VALUES ('1333447953697177602', 'flask', 2);
132 | INSERT INTO `bms_tag` VALUES ('1333676096320106498', 'spring', 1);
133 | INSERT INTO `bms_tag` VALUES ('1333695976742268930', 'django', 1);
134 | INSERT INTO `bms_tag` VALUES ('1334481725519429634', 'security', 1);
135 | INSERT INTO `bms_tag` VALUES ('1349362401597775874', 'tensorflow', 1);
136 | INSERT INTO `bms_tag` VALUES ('1349631541306732545', 'pytorch', 1);
137 |
138 |
139 | -- ----------------------------
140 | -- Table structure for bms_post_tag
141 | -- ----------------------------
142 | DROP TABLE IF EXISTS `bms_post_tag`;
143 | CREATE TABLE `bms_post_tag` (
144 | `id` int NOT NULL AUTO_INCREMENT COMMENT '主键',
145 | `tag_id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '标签ID',
146 | `topic_id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '话题ID',
147 | PRIMARY KEY (`id`) USING BTREE,
148 | INDEX `tag_id`(`tag_id`) USING BTREE,
149 | INDEX `topic_id`(`topic_id`) USING BTREE
150 | ) ENGINE = InnoDB AUTO_INCREMENT = 52 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '话题-标签 中间表' ROW_FORMAT = DYNAMIC;
151 |
152 | -- ----------------------------
153 | -- Records of bms_post_tag
154 | -- ----------------------------
155 | INSERT INTO `bms_post_tag` VALUES (36, '1332650453377708034', '1332650453142827009');
156 | INSERT INTO `bms_post_tag` VALUES (37, '1332681213568589825', '1332681213400817665');
157 | INSERT INTO `bms_post_tag` VALUES (38, '1332681213631504385', '1332681213400817665');
158 | INSERT INTO `bms_post_tag` VALUES (39, '1332682473218744321', '1332682473151635458');
159 | INSERT INTO `bms_post_tag` VALUES (40, '1332913064463794178', '1332913064396685314');
160 | INSERT INTO `bms_post_tag` VALUES (41, '1332913064530903041', '1332913064396685314');
161 | INSERT INTO `bms_post_tag` VALUES (42, '1333432347107143681', '1333432347031646209');
162 | INSERT INTO `bms_post_tag` VALUES (43, '1333432347107143682', '1333432347031646209');
163 | INSERT INTO `bms_post_tag` VALUES (44, '1333447953697177602', '1333447953558765569');
164 | INSERT INTO `bms_post_tag` VALUES (45, '1332913064463794178', '1333668258587750401');
165 | INSERT INTO `bms_post_tag` VALUES (46, '1333676096320106498', '1333676096156528641');
166 | INSERT INTO `bms_post_tag` VALUES (47, '1333695976742268930', '1333695976536748034');
167 | INSERT INTO `bms_post_tag` VALUES (48, '1334481725519429634', '1334481725322297346');
168 | INSERT INTO `bms_post_tag` VALUES (49, '1333447953697177602', '1335149981733449729');
169 | INSERT INTO `bms_post_tag` VALUES (50, '1349362401597775874', '1349362401438392322');
170 | INSERT INTO `bms_post_tag` VALUES (51, '1349631541306732545', '1349631541260595202');
171 |
172 | -- ----------------------------
173 | -- Table structure for bms_promotion
174 | -- ----------------------------
175 | DROP TABLE IF EXISTS `bms_promotion`;
176 | CREATE TABLE `bms_promotion` (
177 | `id` int NOT NULL AUTO_INCREMENT COMMENT '主键',
178 | `title` varchar(255) CHARACTER SET utf8mb4 NULL DEFAULT NULL COMMENT '广告标题',
179 | `link` varchar(255) CHARACTER SET utf8mb4 NULL DEFAULT NULL COMMENT '广告链接',
180 | `description` varchar(255) CHARACTER SET utf8mb4 NULL DEFAULT NULL COMMENT '说明',
181 | PRIMARY KEY (`id`) USING BTREE
182 | ) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COMMENT = '广告推广表' ROW_FORMAT = DYNAMIC;
183 |
184 | -- ----------------------------
185 | -- Records of bms_promotion
186 | -- ----------------------------
187 | INSERT INTO `bms_promotion` VALUES (1, '开发者头条', 'https://juejin.cn/', '开发者头条');
188 | INSERT INTO `bms_promotion` VALUES (2, '并发编程网', 'https://juejin.cn/', '并发编程网');
189 | INSERT INTO `bms_promotion` VALUES (3, '掘金', 'https://juejin.cn/', '掘金');
190 |
191 |
192 | -- ----------------------------
193 | -- Table structure for bms_tip
194 | -- ----------------------------
195 | DROP TABLE IF EXISTS `bms_tip`;
196 | CREATE TABLE `bms_tip` (
197 | `id` int UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
198 | `content` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '内容',
199 | `author` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '作者',
200 | `type` tinyint NOT NULL COMMENT '1:使用,0:过期',
201 | PRIMARY KEY (`id`) USING BTREE
202 | ) ENGINE = InnoDB AUTO_INCREMENT = 24864 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '每日赠言' ROW_FORMAT = DYNAMIC;
203 |
204 | -- ----------------------------
205 | -- Records of bms_tip
206 | -- ----------------------------
207 | INSERT INTO `bms_tip` VALUES (1, '多锉出快锯,多做长知识。', '佚名', 1);
208 | INSERT INTO `bms_tip` VALUES (2, '未来总留着什么给对它抱有信心的人。', '佚名', 1);
209 | INSERT INTO `bms_tip` VALUES (3, '一个人的智慧不够用,两个人的智慧用不完。', '谚语', 1);
210 | INSERT INTO `bms_tip` VALUES (4, '十个指头按不住十个跳蚤', '傣族', 1);
211 | INSERT INTO `bms_tip` VALUES (5, '言不信者,行不果。', '墨子', 1);
212 | INSERT INTO `bms_tip` VALUES (6, '攀援而登,箕踞而遨,则几数州之土壤,皆在衽席之下。', '柳宗元', 1);
213 | INSERT INTO `bms_tip` VALUES (7, '美德大都包含在良好的习惯之内。', '帕利克', 1);
214 | INSERT INTO `bms_tip` VALUES (8, '人有不及,可以情恕。', '《晋书》', 1);
215 | INSERT INTO `bms_tip` VALUES (9, '明·吴惟顺', '法不传六耳', 1);
216 | INSERT INTO `bms_tip` VALUES (10, '真正的朋友应该说真话,不管那话多么尖锐。', '奥斯特洛夫斯基', 1);
217 | INSERT INTO `bms_tip` VALUES (11, '时间是一切财富中最宝贵的财富。', '德奥弗拉斯多', 1);
218 | INSERT INTO `bms_tip` VALUES (12, '看人下菜碟', '民谚', 1);
219 | INSERT INTO `bms_tip` VALUES (13, '如果不是怕别人反感,女人决不会保持完整的严肃。', '拉罗什福科', 1);
220 | INSERT INTO `bms_tip` VALUES (14, '爱是春暖花开时对你满满的笑意', '佚名', 1);
221 | INSERT INTO `bms_tip` VALUES (15, '希望是坚韧的拐杖,忍耐是旅行袋,携带它们,人可以登上永恒之旅。', '罗素', 1);
222 | INSERT INTO `bms_tip` VALUES (18, '天国般的幸福,存在于对真爱的希望。', '佚名', 1);
223 | INSERT INTO `bms_tip` VALUES (19, '我们现在必须完全保持党的纪律,否则一切都会陷入污泥中。', '马克思', 1);
224 | INSERT INTO `bms_tip` VALUES (20, '在科学上没有平坦的大道,只有不畏劳苦沿着陡峭山路攀登的人,才有希望达到光辉的顶点。', '马克思', 1);
225 | INSERT INTO `bms_tip` VALUES (21, '懒惰的马嫌路远', '蒙古', 1);
226 | INSERT INTO `bms_tip` VALUES (22, '别忘记热水是由冷水烧成的', '非洲', 1);
227 |
228 |
229 | -- ----------------------------
230 | -- Table structure for ums_user
231 | -- ----------------------------
232 | DROP TABLE IF EXISTS `ums_user`;
233 | CREATE TABLE `ums_user` (
234 | `id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户ID',
235 | `username` varchar(15) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '用户名',
236 | `alias` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户昵称',
237 | `password` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '密码',
238 | `avatar` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '头像',
239 | `email` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '邮箱',
240 | `mobile` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '手机',
241 | `score` int NOT NULL DEFAULT 0 COMMENT '积分',
242 | `token` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT 'token',
243 | `bio` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '个人简介',
244 | `active` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否激活,1:是,0:否',
245 | `status` bit(1) NULL DEFAULT b'1' COMMENT '状态,1:使用,0:停用',
246 | `role_id` int NULL DEFAULT NULL COMMENT '用户角色',
247 | `create_time` datetime NOT NULL COMMENT '加入时间',
248 | `modify_time` datetime NULL DEFAULT NULL COMMENT '修改时间',
249 | PRIMARY KEY (`id`) USING BTREE,
250 | UNIQUE INDEX `user_name`(`username`) USING BTREE,
251 | INDEX `user_email`(`email`) USING BTREE,
252 | INDEX `user_create_time`(`create_time`) USING BTREE
253 | ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '用户表' ROW_FORMAT = DYNAMIC;
254 |
255 | -- ----------------------------
256 | -- Records of ums_user
257 | -- ----------------------------
258 | INSERT INTO `ums_user` VALUES ('1349290158897311745', 'admin', 'admin', '$2a$10$8qx711TBg/2hxfL7N.sxf.0ROMhR/iuPhQx33IFqGd7PLgt5nGJTO', 'https://s3.ax1x.com/2020/12/01/DfHNo4.jpg', '23456@qq.com', NULL, 2, '', '自由职业者', b'1', b'1', NULL, '2021-01-13 17:40:17', NULL);
259 | INSERT INTO `ums_user` VALUES ('1349618748226658305', 'zhangsan', 'zhangsan', '$2a$10$7K3yYv8sMV5Xsc2facXTcuyDo8JQ4FJHvjZ7qtWYcJdei3Q6Fvqdm', 'https://s3.ax1x.com/2020/12/01/DfHNo4.jpg', '23456@qq.com', NULL, 0, '', '自由职业者', b'1', b'1', NULL, '2021-01-14 15:25:59', NULL);
260 |
261 | SET FOREIGN_KEY_CHECKS = 1;
262 |
--------------------------------------------------------------------------------
/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # https://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59 | if [ -z "$JAVA_HOME" ]; then
60 | if [ -x "/usr/libexec/java_home" ]; then
61 | export JAVA_HOME="`/usr/libexec/java_home`"
62 | else
63 | export JAVA_HOME="/Library/Java/Home"
64 | fi
65 | fi
66 | ;;
67 | esac
68 |
69 | if [ -z "$JAVA_HOME" ] ; then
70 | if [ -r /etc/gentoo-release ] ; then
71 | JAVA_HOME=`java-config --jre-home`
72 | fi
73 | fi
74 |
75 | if [ -z "$M2_HOME" ] ; then
76 | ## resolve links - $0 may be a link to maven's home
77 | PRG="$0"
78 |
79 | # need this for relative symlinks
80 | while [ -h "$PRG" ] ; do
81 | ls=`ls -ld "$PRG"`
82 | link=`expr "$ls" : '.*-> \(.*\)$'`
83 | if expr "$link" : '/.*' > /dev/null; then
84 | PRG="$link"
85 | else
86 | PRG="`dirname "$PRG"`/$link"
87 | fi
88 | done
89 |
90 | saveddir=`pwd`
91 |
92 | M2_HOME=`dirname "$PRG"`/..
93 |
94 | # make it fully qualified
95 | M2_HOME=`cd "$M2_HOME" && pwd`
96 |
97 | cd "$saveddir"
98 | # echo Using m2 at $M2_HOME
99 | fi
100 |
101 | # For Cygwin, ensure paths are in UNIX format before anything is touched
102 | if $cygwin ; then
103 | [ -n "$M2_HOME" ] &&
104 | M2_HOME=`cygpath --unix "$M2_HOME"`
105 | [ -n "$JAVA_HOME" ] &&
106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107 | [ -n "$CLASSPATH" ] &&
108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109 | fi
110 |
111 | # For Mingw, ensure paths are in UNIX format before anything is touched
112 | if $mingw ; then
113 | [ -n "$M2_HOME" ] &&
114 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
115 | [ -n "$JAVA_HOME" ] &&
116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117 | fi
118 |
119 | if [ -z "$JAVA_HOME" ]; then
120 | javaExecutable="`which javac`"
121 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
122 | # readlink(1) is not available as standard on Solaris 10.
123 | readLink=`which readlink`
124 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
125 | if $darwin ; then
126 | javaHome="`dirname \"$javaExecutable\"`"
127 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
128 | else
129 | javaExecutable="`readlink -f \"$javaExecutable\"`"
130 | fi
131 | javaHome="`dirname \"$javaExecutable\"`"
132 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
133 | JAVA_HOME="$javaHome"
134 | export JAVA_HOME
135 | fi
136 | fi
137 | fi
138 |
139 | if [ -z "$JAVACMD" ] ; then
140 | if [ -n "$JAVA_HOME" ] ; then
141 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
142 | # IBM's JDK on AIX uses strange locations for the executables
143 | JAVACMD="$JAVA_HOME/jre/sh/java"
144 | else
145 | JAVACMD="$JAVA_HOME/bin/java"
146 | fi
147 | else
148 | JAVACMD="`which java`"
149 | fi
150 | fi
151 |
152 | if [ ! -x "$JAVACMD" ] ; then
153 | echo "Error: JAVA_HOME is not defined correctly." >&2
154 | echo " We cannot execute $JAVACMD" >&2
155 | exit 1
156 | fi
157 |
158 | if [ -z "$JAVA_HOME" ] ; then
159 | echo "Warning: JAVA_HOME environment variable is not set."
160 | fi
161 |
162 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
163 |
164 | # traverses directory structure from process work directory to filesystem root
165 | # first directory with .mvn subdirectory is considered project base directory
166 | find_maven_basedir() {
167 |
168 | if [ -z "$1" ]
169 | then
170 | echo "Path not specified to find_maven_basedir"
171 | return 1
172 | fi
173 |
174 | basedir="$1"
175 | wdir="$1"
176 | while [ "$wdir" != '/' ] ; do
177 | if [ -d "$wdir"/.mvn ] ; then
178 | basedir=$wdir
179 | break
180 | fi
181 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
182 | if [ -d "${wdir}" ]; then
183 | wdir=`cd "$wdir/.."; pwd`
184 | fi
185 | # end of workaround
186 | done
187 | echo "${basedir}"
188 | }
189 |
190 | # concatenates all lines of a file
191 | concat_lines() {
192 | if [ -f "$1" ]; then
193 | echo "$(tr -s '\n' ' ' < "$1")"
194 | fi
195 | }
196 |
197 | BASE_DIR=`find_maven_basedir "$(pwd)"`
198 | if [ -z "$BASE_DIR" ]; then
199 | exit 1;
200 | fi
201 |
202 | ##########################################################################################
203 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
204 | # This allows using the maven wrapper in projects that prohibit checking in binary data.
205 | ##########################################################################################
206 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
207 | if [ "$MVNW_VERBOSE" = true ]; then
208 | echo "Found .mvn/wrapper/maven-wrapper.jar"
209 | fi
210 | else
211 | if [ "$MVNW_VERBOSE" = true ]; then
212 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
213 | fi
214 | if [ -n "$MVNW_REPOURL" ]; then
215 | jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
216 | else
217 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
218 | fi
219 | while IFS="=" read key value; do
220 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
221 | esac
222 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
223 | if [ "$MVNW_VERBOSE" = true ]; then
224 | echo "Downloading from: $jarUrl"
225 | fi
226 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
227 | if $cygwin; then
228 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
229 | fi
230 |
231 | if command -v wget > /dev/null; then
232 | if [ "$MVNW_VERBOSE" = true ]; then
233 | echo "Found wget ... using wget"
234 | fi
235 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
236 | wget "$jarUrl" -O "$wrapperJarPath"
237 | else
238 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath"
239 | fi
240 | elif command -v curl > /dev/null; then
241 | if [ "$MVNW_VERBOSE" = true ]; then
242 | echo "Found curl ... using curl"
243 | fi
244 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
245 | curl -o "$wrapperJarPath" "$jarUrl" -f
246 | else
247 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
248 | fi
249 |
250 | else
251 | if [ "$MVNW_VERBOSE" = true ]; then
252 | echo "Falling back to using Java to download"
253 | fi
254 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
255 | # For Cygwin, switch paths to Windows format before running javac
256 | if $cygwin; then
257 | javaClass=`cygpath --path --windows "$javaClass"`
258 | fi
259 | if [ -e "$javaClass" ]; then
260 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
261 | if [ "$MVNW_VERBOSE" = true ]; then
262 | echo " - Compiling MavenWrapperDownloader.java ..."
263 | fi
264 | # Compiling the Java class
265 | ("$JAVA_HOME/bin/javac" "$javaClass")
266 | fi
267 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
268 | # Running the downloader
269 | if [ "$MVNW_VERBOSE" = true ]; then
270 | echo " - Running MavenWrapperDownloader.java ..."
271 | fi
272 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
273 | fi
274 | fi
275 | fi
276 | fi
277 | ##########################################################################################
278 | # End of extension
279 | ##########################################################################################
280 |
281 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
282 | if [ "$MVNW_VERBOSE" = true ]; then
283 | echo $MAVEN_PROJECTBASEDIR
284 | fi
285 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
286 |
287 | # For Cygwin, switch paths to Windows format before running java
288 | if $cygwin; then
289 | [ -n "$M2_HOME" ] &&
290 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
291 | [ -n "$JAVA_HOME" ] &&
292 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
293 | [ -n "$CLASSPATH" ] &&
294 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
295 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
296 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
297 | fi
298 |
299 | # Provide a "standardized" way to retrieve the CLI args that will
300 | # work with both Windows and non-Windows executions.
301 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
302 | export MAVEN_CMD_LINE_ARGS
303 |
304 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
305 |
306 | exec "$JAVACMD" \
307 | $MAVEN_OPTS \
308 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
309 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
310 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
311 |
--------------------------------------------------------------------------------
/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM https://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM set title of command window
39 | title %0
40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
42 |
43 | @REM set %HOME% to equivalent of $HOME
44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
45 |
46 | @REM Execute a user defined script before this one
47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
51 | :skipRcPre
52 |
53 | @setlocal
54 |
55 | set ERROR_CODE=0
56 |
57 | @REM To isolate internal variables from possible post scripts, we use another setlocal
58 | @setlocal
59 |
60 | @REM ==== START VALIDATION ====
61 | if not "%JAVA_HOME%" == "" goto OkJHome
62 |
63 | echo.
64 | echo Error: JAVA_HOME not found in your environment. >&2
65 | echo Please set the JAVA_HOME variable in your environment to match the >&2
66 | echo location of your Java installation. >&2
67 | echo.
68 | goto error
69 |
70 | :OkJHome
71 | if exist "%JAVA_HOME%\bin\java.exe" goto init
72 |
73 | echo.
74 | echo Error: JAVA_HOME is set to an invalid directory. >&2
75 | echo JAVA_HOME = "%JAVA_HOME%" >&2
76 | echo Please set the JAVA_HOME variable in your environment to match the >&2
77 | echo location of your Java installation. >&2
78 | echo.
79 | goto error
80 |
81 | @REM ==== END VALIDATION ====
82 |
83 | :init
84 |
85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
86 | @REM Fallback to current working directory if not found.
87 |
88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
90 |
91 | set EXEC_DIR=%CD%
92 | set WDIR=%EXEC_DIR%
93 | :findBaseDir
94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
95 | cd ..
96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
97 | set WDIR=%CD%
98 | goto findBaseDir
99 |
100 | :baseDirFound
101 | set MAVEN_PROJECTBASEDIR=%WDIR%
102 | cd "%EXEC_DIR%"
103 | goto endDetectBaseDir
104 |
105 | :baseDirNotFound
106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
107 | cd "%EXEC_DIR%"
108 |
109 | :endDetectBaseDir
110 |
111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
112 |
113 | @setlocal EnableExtensions EnableDelayedExpansion
114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
116 |
117 | :endReadAdditionalConfig
118 |
119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
122 |
123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
124 |
125 | FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
127 | )
128 |
129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data.
131 | if exist %WRAPPER_JAR% (
132 | if "%MVNW_VERBOSE%" == "true" (
133 | echo Found %WRAPPER_JAR%
134 | )
135 | ) else (
136 | if not "%MVNW_REPOURL%" == "" (
137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
138 | )
139 | if "%MVNW_VERBOSE%" == "true" (
140 | echo Couldn't find %WRAPPER_JAR%, downloading it ...
141 | echo Downloading from: %DOWNLOAD_URL%
142 | )
143 |
144 | powershell -Command "&{"^
145 | "$webclient = new-object System.Net.WebClient;"^
146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
148 | "}"^
149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
150 | "}"
151 | if "%MVNW_VERBOSE%" == "true" (
152 | echo Finished downloading %WRAPPER_JAR%
153 | )
154 | )
155 | @REM End of extension
156 |
157 | @REM Provide a "standardized" way to retrieve the CLI args that will
158 | @REM work with both Windows and non-Windows executions.
159 | set MAVEN_CMD_LINE_ARGS=%*
160 |
161 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
162 | if ERRORLEVEL 1 goto error
163 | goto end
164 |
165 | :error
166 | set ERROR_CODE=1
167 |
168 | :end
169 | @endlocal & set ERROR_CODE=%ERROR_CODE%
170 |
171 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
172 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
173 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
174 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
175 | :skipRcPost
176 |
177 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
178 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
179 |
180 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
181 |
182 | exit /B %ERROR_CODE%
183 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.3.8.RELEASE
9 |
10 |
11 | com.douyuehan
12 | doubao
13 | 0.0.1-SNAPSHOT
14 | doubao
15 | Demo project for Spring Boot
16 |
17 | 1.8
18 | UTF-8
19 | UTF-8
20 | 3.4.2
21 | 1.2.75
22 | 5.5.7
23 | 0.9.1
24 | 5.1.1
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-web
36 |
37 |
38 |
39 | org.projectlombok
40 | lombok
41 | true
42 |
43 |
44 |
45 |
46 | io.jsonwebtoken
47 | jjwt
48 | ${jwt.version}
49 |
50 |
51 |
52 | com.vdurmont
53 | emoji-java
54 | ${emoji-java.version}
55 |
56 |
57 |
58 | org.apache.commons
59 | commons-pool2
60 |
61 |
62 |
63 | cn.hutool
64 | hutool-all
65 | ${hutool.version}
66 |
67 |
68 |
69 | mysql
70 | mysql-connector-java
71 | runtime
72 |
73 |
74 |
75 | com.baomidou
76 | mybatis-plus-boot-starter
77 | ${mybatis-plus.version}
78 |
79 |
80 |
81 | com.alibaba
82 | fastjson
83 | ${fastjson.version}
84 |
85 |
86 |
87 | org.springframework.boot
88 | spring-boot-configuration-processor
89 | true
90 |
91 |
92 |
93 |
94 | org.hibernate.validator
95 | hibernate-validator
96 |
97 |
98 |
99 | org.springframework.boot
100 | spring-boot-starter-test
101 | test
102 |
103 |
104 | org.junit.vintage
105 | junit-vintage-engine
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 | org.springframework.boot
115 | spring-boot-maven-plugin
116 |
117 |
118 |
119 | org.projectlombok
120 | lombok
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
--------------------------------------------------------------------------------
/src/main/java/com/douyuehan/doubao/DoubaoApplication.java:
--------------------------------------------------------------------------------
1 | package com.douyuehan.doubao;
2 |
3 | import com.douyuehan.doubao.jwt.JwtAuthenticationFilter;
4 | import org.mybatis.spring.annotation.MapperScan;
5 | import org.springframework.boot.SpringApplication;
6 | import org.springframework.boot.autoconfigure.SpringBootApplication;
7 | import org.springframework.boot.builder.SpringApplicationBuilder;
8 | import org.springframework.boot.web.servlet.FilterRegistrationBean;
9 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
10 | import org.springframework.cache.annotation.EnableCaching;
11 | import org.springframework.context.annotation.Bean;
12 |
13 | @MapperScan("com.douyuehan.doubao.mapper")
14 | @SpringBootApplication
15 | public class DoubaoApplication extends SpringBootServletInitializer {
16 | @Override
17 | protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
18 | return builder.sources(DoubaoApplication.class);
19 | }
20 | @Bean
21 | public FilterRegistrationBean jwtFilter() {
22 | final FilterRegistrationBean registrationBean = new FilterRegistrationBean();
23 | JwtAuthenticationFilter filter = new JwtAuthenticationFilter();
24 | registrationBean.setFilter(filter);
25 | return registrationBean;
26 | }
27 |
28 | public static void main(String[] args) {
29 | SpringApplication.run(DoubaoApplication.class, args);
30 | }
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/src/main/java/com/douyuehan/doubao/common/api/ApiErrorCode.java:
--------------------------------------------------------------------------------
1 | package com.douyuehan.doubao.common.api;
2 |
3 |
4 | public enum ApiErrorCode implements IErrorCode {
5 |
6 | /**
7 | * 成功
8 | */
9 | SUCCESS(200, "操作成功"),
10 | /**
11 | * 失败
12 | */
13 | FAILED(-1, "操作失败"),
14 | /**
15 | * 未登录,Token过期
16 | */
17 | UNAUTHORIZED(401, "暂未登录或token已经过期"),
18 | /**
19 | * 权限不足
20 | */
21 | FORBIDDEN(403, "权限不足"),
22 | /**
23 | * 参数校验错误
24 | */
25 | VALIDATE_FAILED(404, "参数检验失败");
26 |
27 | private final Integer code;
28 | private final String message;
29 |
30 | ApiErrorCode(int code, String message) {
31 | this.code = code;
32 | this.message = message;
33 | }
34 |
35 | @Override
36 | public Integer getCode() {
37 | return code;
38 | }
39 |
40 | @Override
41 | public String getMessage() {
42 | return message;
43 | }
44 |
45 | @Override
46 | public String toString() {
47 | return "ApiErrorCode{" +
48 | "code=" + code +
49 | ", message='" + message + '\'' +
50 | '}';
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/com/douyuehan/doubao/common/api/ApiResult.java:
--------------------------------------------------------------------------------
1 | package com.douyuehan.doubao.common.api;
2 |
3 |
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | import java.io.Serializable;
8 | import java.util.Optional;
9 |
10 |
11 | @Data
12 | @NoArgsConstructor
13 | public class ApiResult implements Serializable {
14 |
15 | private static final long serialVersionUID = -4153430394359594346L;
16 | /**
17 | * 业务状态码
18 | */
19 | private long code;
20 | /**
21 | * 结果集
22 | */
23 | private T data;
24 | /**
25 | * 接口描述
26 | */
27 | private String message;
28 |
29 | /**
30 | * 全参
31 | *
32 | * @param code 业务状态码
33 | * @param message 描述
34 | * @param data 结果集
35 | */
36 | public ApiResult(long code, String message, T data) {
37 | this.code = code;
38 | this.message = message;
39 | this.data = data;
40 | }
41 |
42 | public ApiResult(IErrorCode errorCode) {
43 | errorCode = Optional.ofNullable(errorCode).orElse(ApiErrorCode.FAILED);
44 | this.code = errorCode.getCode();
45 | this.message = errorCode.getMessage();
46 | }
47 |
48 | /**
49 | * 成功
50 | *
51 | * @param data 结果集
52 | * @return {code:200,message:操作成功,data:自定义}
53 | */
54 | public static ApiResult success() {
55 | return new ApiResult(ApiErrorCode.SUCCESS.getCode(), ApiErrorCode.SUCCESS.getMessage(), null);
56 | }
57 |
58 | /**
59 | * 成功
60 | *
61 | * @param data 结果集
62 | * @return {code:200,message:操作成功,data:自定义}
63 | */
64 | public static ApiResult success(T data) {
65 | return new ApiResult(ApiErrorCode.SUCCESS.getCode(), ApiErrorCode.SUCCESS.getMessage(), data);
66 | }
67 |
68 | /**
69 | * 成功
70 | *
71 | * @param data 结果集
72 | * @param message 自定义提示信息
73 | * @return {code:200,message:自定义,data:自定义}
74 | */
75 | public static ApiResult success(T data, String message) {
76 | return new ApiResult(ApiErrorCode.SUCCESS.getCode(), message, data);
77 | }
78 |
79 | /**
80 | * 失败返回结果
81 | */
82 | public static ApiResult failed() {
83 | return failed(ApiErrorCode.FAILED);
84 | }
85 |
86 | /**
87 | * 失败返回结果
88 | *
89 | * @param message 提示信息
90 | * @return {code:枚举ApiErrorCode取,message:自定义,data:null}
91 | */
92 | public static ApiResult failed(String message) {
93 | return new ApiResult(ApiErrorCode.FAILED.getCode(), message, null);
94 | }
95 |
96 | /**
97 | * 失败
98 | *
99 | * @param errorCode 错误码
100 | * @return {code:封装接口取,message:封装接口取,data:null}
101 | */
102 | public static ApiResult failed(IErrorCode errorCode) {
103 | return new ApiResult(errorCode.getCode(), errorCode.getMessage(), null);
104 | }
105 |
106 | /**
107 | * 失败返回结果
108 | *
109 | * @param errorCode 错误码
110 | * @param message 错误信息
111 | * @return {code:枚举ApiErrorCode取,message:自定义,data:null}
112 | */
113 | public static ApiResult failed(IErrorCode errorCode, String message) {
114 | return new ApiResult(errorCode.getCode(), message, null);
115 | }
116 |
117 | /**
118 | * 参数验证失败返回结果
119 | */
120 | public static ApiResult validateFailed() {
121 | return failed(ApiErrorCode.VALIDATE_FAILED);
122 | }
123 |
124 | /**
125 | * 参数验证失败返回结果
126 | *
127 | * @param message 提示信息
128 | */
129 | public static ApiResult validateFailed(String message) {
130 | return new ApiResult(ApiErrorCode.VALIDATE_FAILED.getCode(), message, null);
131 | }
132 |
133 | /**
134 | * 未登录返回结果
135 | */
136 | public static ApiResult unauthorized(T data) {
137 | return new ApiResult(ApiErrorCode.UNAUTHORIZED.getCode(), ApiErrorCode.UNAUTHORIZED.getMessage(), data);
138 | }
139 |
140 | /**
141 | * 未授权返回结果
142 | */
143 | public static ApiResult forbidden(T data) {
144 | return new ApiResult(ApiErrorCode.FORBIDDEN.getCode(), ApiErrorCode.FORBIDDEN.getMessage(), data);
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/src/main/java/com/douyuehan/doubao/common/api/IErrorCode.java:
--------------------------------------------------------------------------------
1 | package com.douyuehan.doubao.common.api;
2 |
3 |
4 | public interface IErrorCode {
5 | /**
6 | * 错误编码: -1失败;200成功
7 | *
8 | * @return 错误编码
9 | */
10 | Integer getCode();
11 |
12 | /**
13 | * 错误描述
14 | *
15 | * @return 错误描述
16 | */
17 | String getMessage();
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/douyuehan/doubao/common/exception/ApiAsserts.java:
--------------------------------------------------------------------------------
1 | package com.douyuehan.doubao.common.exception;
2 |
3 | import com.douyuehan.doubao.common.api.IErrorCode;
4 |
5 |
6 | public class ApiAsserts {
7 | /**
8 | * 抛失败异常
9 | *
10 | * @param message 说明
11 | */
12 | public static void fail(String message) {
13 | throw new ApiException(message);
14 | }
15 |
16 | /**
17 | * 抛失败异常
18 | *
19 | * @param errorCode 状态码
20 | */
21 | public static void fail(IErrorCode errorCode) {
22 | throw new ApiException(errorCode);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/com/douyuehan/doubao/common/exception/ApiException.java:
--------------------------------------------------------------------------------
1 | package com.douyuehan.doubao.common.exception;
2 |
3 | import com.douyuehan.doubao.common.api.IErrorCode;
4 |
5 |
6 | public class ApiException extends RuntimeException {
7 | private IErrorCode errorCode;
8 |
9 | public ApiException(IErrorCode errorCode) {
10 | super(errorCode.getMessage());
11 | this.errorCode = errorCode;
12 | }
13 |
14 | public ApiException(String message) {
15 | super(message);
16 | }
17 |
18 | public IErrorCode getErrorCode() {
19 | return errorCode;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/com/douyuehan/doubao/common/exception/GlobalExceptionHandler.java:
--------------------------------------------------------------------------------
1 | package com.douyuehan.doubao.common.exception;//package com.knox.aurora.common.exception;
2 |
3 | import com.douyuehan.doubao.common.api.ApiResult;
4 | import org.springframework.web.bind.annotation.ControllerAdvice;
5 | import org.springframework.web.bind.annotation.ExceptionHandler;
6 | import org.springframework.web.bind.annotation.ResponseBody;
7 |
8 | import java.util.Map;
9 |
10 | @ControllerAdvice
11 | public class GlobalExceptionHandler {
12 | /**
13 | * 捕获自定义异常
14 | */
15 | @ResponseBody
16 | @ExceptionHandler(value = ApiException.class)
17 | public ApiResult