{"id":352099,"date":"2021-02-10T06:59:09","date_gmt":"2021-02-09T22:59:09","guid":{"rendered":"http:\/\/4563.org\/?p=352099"},"modified":"2021-02-24T16:37:08","modified_gmt":"2021-02-24T08:37:08","slug":"springbootvue-%e8%b1%86%e5%ae%9d%e7%a4%be%e5%8c%ba%e5%89%8d%e5%90%8e%e7%ab%af%e5%88%86%e7%a6%bb%e9%a1%b9%e7%9b%ae%e6%89%8b%e6%8a%8a%e6%89%8b%e5%ae%9e%e6%88%98%e7%b3%bb%e5%88%97%e6%95%99%e7%a8%8b-02","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=352099","title":{"rendered":"SpringBoot+Vue \u8c46\u5b9d\u793e\u533a\u524d\u540e\u7aef\u5206\u79bb\u9879\u76ee\u624b\u628a\u624b\u5b9e\u6218\u7cfb\u5217\u6559\u7a0b 02&#8212;\u521b\u5efa\u540e\u7aef\u5de5\u7a0b"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  SpringBoot+Vue \u8c46\u5b9d\u793e\u533a\u524d\u540e\u7aef\u5206\u79bb\u9879\u76ee\u624b\u628a\u624b\u5b9e\u6218\u7cfb\u5217\u6559\u7a0b 02&#8212;\u521b\u5efa\u540e\u7aef\u5de5\u7a0b               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : songboriceboy <\/span>  <span><i><\/i> 2<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<h2>\u8c46\u5b9d\u793e\u533a\u9879\u76ee\u5b9e\u6218\u6559\u7a0b\u7b80\u4ecb<\/h2>\n<p>\u672c\u9879\u76ee\u5b9e\u6218\u6559\u7a0b\u914d\u6709\u514d\u8d39\u89c6\u9891\u6559\u7a0b\uff0c\u914d\u5957\u4ee3\u7801\u5b8c\u5168\u5f00\u6e90\u3002\u624b\u628a\u624b\u4ece\u96f6\u5f00\u59cb\u642d\u5efa\u4e00\u4e2a\u76ee\u524d\u5e94\u7528\u6700\u5e7f\u6cdb\u7684 Springboot+Vue \u524d\u540e\u7aef\u5206\u79bb\u591a\u7528\u6237\u793e\u533a\u9879\u76ee\u3002\u672c\u9879\u76ee\u96be\u5ea6\u9002\u4e2d\uff0c\u4e3a\u4fbf\u4e8e\u5927\u5bb6\u5b66\u4e60\uff0c\u6bcf\u4e00\u96c6\u89c6\u9891\u6559\u7a0b\u5bf9\u5e94\u5728 Github \u4e0a\u7684\u6bcf\u4e00\u6b21\u63d0\u4ea4\u3002<\/p>\n<h3>\u9879\u76ee\u9996\u9875\u622a\u56fe<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2021\/02\/061bf0d74dc34f3a832d879ff9d1fbe3tplv-k3u1fbpfcp-zoom-1.image_.png\" alt=\"SpringBoot+Vue \u8c46\u5b9d\u793e\u533a\u524d\u540e\u7aef\u5206\u79bb\u9879\u76ee\u624b\u628a\u624b\u5b9e\u6218\u7cfb\u5217\u6559\u7a0b 02---\u521b\u5efa\u540e\u7aef\u5de5\u7a0b\" \/><\/p>\n<h3>\u4ee3\u7801\u5f00\u6e90\u5730\u5740<\/h3>\n<p>\u524d\u7aef \u540e\u7aef<\/p>\n<h3>\u89c6\u9891\u6559\u7a0b\u5730\u5740<\/h3>\n<p>\u89c6\u9891\u6559\u7a0b<\/p>\n<h3>\u524d\u7aef\u6280\u672f\u6808<\/h3>\n<p>Vue Vuex Vue Router Axios Bulma Buefy Element Vditor DarkReader<\/p>\n<h3>\u540e\u7aef\u6280\u672f\u6808<\/h3>\n<p>Spring Boot Mysql Mybatis MyBatis-Plus Spring Security JWT Lombok<\/p>\n<h2>\u642d\u5efa\u540e\u7aef\u5de5\u7a0b<\/h2>\n<h3>0.\u5bfc\u5165 sql<\/h3>\n<p><strong>\u5728\u6570\u636e\u5e93\u5bfc\u5165<\/strong><\/p>\n<pre><code>\/*  Navicat Premium Data Transfer  Source Server         : localhost  Source Server Type    : MySQL  Source Server Version : 80022  Source Host           : localhost:3306  Source Schema         : doubao  Target Server Type    : MySQL  Target Server Version : 80022  File Encoding         : 65001 *\/  SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0;  -- ---------------------------- -- Table structure for bms_billboard -- ---------------------------- DROP TABLE IF EXISTS `bms_billboard`; CREATE TABLE `bms_billboard`  (   `id` int NOT NULL AUTO_INCREMENT COMMENT '\u4e3b\u952e',   `content` varchar(255) CHARACTER SET utf8mb4 NOT NULL COMMENT '\u516c\u544a',   `create_time` datetime NULL DEFAULT NULL COMMENT '\u516c\u544a\u65f6\u95f4',   `show` tinyint(1) NULL DEFAULT NULL COMMENT '1\uff1a\u5c55\u793a\u4e2d\uff0c0\uff1a\u8fc7\u671f',   PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8mb4  COMMENT = '\u5168\u7ad9\u516c\u544a' ROW_FORMAT = DYNAMIC;  -- ---------------------------- -- Records of bms_billboard -- ---------------------------- INSERT INTO `bms_billboard` VALUES (2, 'R1.0 \u5f00\u59cb\u5df2\u5b9e\u73b0\u62a4\u773c\u6a21\u5f0f ,\u5988\u5988\u518d\u4e5f\u4e0d\u7528\u62c5\u5fc3\u6211\u7684\u773c\u775b\u4e86\u3002', '2020-11-19 17:16:19', 0); INSERT INTO `bms_billboard` VALUES (4, '\u7cfb\u7edf\u5df2\u66f4\u65b0\u81f3\u6700\u65b0\u7248 1.0.1', NULL, 1);   -- ---------------------------- -- Table structure for bms_follow -- ---------------------------- DROP TABLE IF EXISTS `bms_follow`; CREATE TABLE `bms_follow`  (   `id` int NOT NULL AUTO_INCREMENT COMMENT '\u4e3b\u952e',   `parent_id` varchar(20) CHARACTER SET utf8mb4 NULL DEFAULT NULL COMMENT '\u88ab\u5173\u6ce8\u4eba ID',   `follower_id` varchar(20) CHARACTER SET utf8mb4 NULL DEFAULT NULL COMMENT '\u5173\u6ce8\u4eba ID',   PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 130 CHARACTER SET = utf8mb4  COMMENT = '\u7528\u6237\u5173\u6ce8' ROW_FORMAT = DYNAMIC;  -- ---------------------------- -- Records of bms_follow -- ---------------------------- INSERT INTO `bms_follow` VALUES (65, '1329723594994229250', '1317498859501797378'); INSERT INTO `bms_follow` VALUES (85, '1332912847614083073', '1332636310897664002'); INSERT INTO `bms_follow` VALUES (129, '1349290158897311745', '1349618748226658305');  -- ---------------------------- -- Table structure for bms_post -- ---------------------------- DROP TABLE IF EXISTS `bms_post`; CREATE TABLE `bms_post`  (   `id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '\u4e3b\u952e',   `title` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '\u6807\u9898',   `content` longtext CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT 'markdown \u5185\u5bb9',   `user_id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '\u4f5c\u8005 ID',   `comments` int NOT NULL DEFAULT 0 COMMENT '\u8bc4\u8bba\u7edf\u8ba1',   `collects` int NOT NULL DEFAULT 0 COMMENT '\u6536\u85cf\u7edf\u8ba1',   `view` int NOT NULL DEFAULT 0 COMMENT '\u6d4f\u89c8\u7edf\u8ba1',   `top` bit(1) NOT NULL DEFAULT b'0' COMMENT '\u662f\u5426\u7f6e\u9876\uff0c1-\u662f\uff0c0-\u5426',   `essence` bit(1) NOT NULL DEFAULT b'0' COMMENT '\u662f\u5426\u52a0\u7cbe\uff0c1-\u662f\uff0c0-\u5426',   `section_id` int NULL DEFAULT 0 COMMENT '\u4e13\u680f ID',   `create_time` datetime NOT NULL COMMENT '\u53d1\u5e03\u65f6\u95f4',   `modify_time` datetime NULL DEFAULT NULL COMMENT '\u4fee\u6539\u65f6\u95f4',   UNIQUE INDEX `title`(`title`) USING BTREE,   INDEX `user_id`(`user_id`) USING BTREE,   INDEX `create_time`(`create_time`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '\u8bdd\u9898\u8868' ROW_FORMAT = DYNAMIC;  -- ---------------------------- -- Table structure for bms_comment -- ---------------------------- DROP TABLE IF EXISTS `bms_comment`; CREATE TABLE `bms_comment`  (   `id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '\u4e3b\u952e',   `content` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '\u5185\u5bb9',   `user_id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '\u4f5c\u8005 ID',   `topic_id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'topic_id',   `create_time` datetime NOT NULL COMMENT '\u53d1\u5e03\u65f6\u95f4',   `modify_time` datetime NULL DEFAULT NULL COMMENT '\u4fee\u6539\u65f6\u95f4',   PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '\u8bc4\u8bba\u8868' ROW_FORMAT = DYNAMIC;  -- ---------------------------- -- Table structure for ums_user -- ---------------------------- DROP TABLE IF EXISTS `ums_user`; CREATE TABLE `ums_user`  (   `id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '\u7528\u6237 ID',   `username` varchar(15) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '\u7528\u6237\u540d',   `alias` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '\u7528\u6237\u6635\u79f0',   `password` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '\u5bc6\u7801',   `avatar` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '\u5934\u50cf',   `email` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '\u90ae\u7bb1',   `mobile` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '\u624b\u673a',   `score` int NOT NULL DEFAULT 0 COMMENT '\u79ef\u5206',   `token` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT 'token',   `bio` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '\u4e2a\u4eba\u7b80\u4ecb',   `active` bit(1) NOT NULL DEFAULT b'0' COMMENT '\u662f\u5426\u6fc0\u6d3b\uff0c1\uff1a\u662f\uff0c0\uff1a\u5426',   `status` bit(1) NULL DEFAULT b'1' COMMENT '\u72b6\u6001\uff0c1\uff1a\u4f7f\u7528\uff0c0\uff1a\u505c\u7528',   `role_id` int NULL DEFAULT NULL COMMENT '\u7528\u6237\u89d2\u8272',   `create_time` datetime NOT NULL COMMENT '\u52a0\u5165\u65f6\u95f4',   `modify_time` datetime NULL DEFAULT NULL COMMENT '\u4fee\u6539\u65f6\u95f4',   PRIMARY KEY (`id`) USING BTREE,   UNIQUE INDEX `user_name`(`username`) USING BTREE,   INDEX `user_email`(`email`) USING BTREE,   INDEX `user_create_time`(`create_time`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '\u7528\u6237\u8868' ROW_FORMAT = DYNAMIC;  -- ---------------------------- -- Records of ums_user -- ---------------------------- INSERT INTO `ums_user` VALUES ('1349290158897311745', 'admin', 'admin', '$2a$10$8qx711TBg\/2hxfL7N.sxf.0ROMhR\/iuPhQx33IFqGd7PLgt5nGJTO', 'https:\/\/s3.ax1x.com\/2020\/12\/01\/DfHNo4.jpg', '[email&#160;protected]', NULL, 2, '', '\u81ea\u7531\u804c\u4e1a\u8005', b'1', b'1', NULL, '2021-01-13 17:40:17', NULL); INSERT INTO `ums_user` VALUES ('1349618748226658305', 'zhangsan', 'zhangsan', '$2a$10$7K3yYv8sMV5Xsc2facXTcuyDo8JQ4FJHvjZ7qtWYcJdei3Q6Fvqdm', 'https:\/\/s3.ax1x.com\/2020\/12\/01\/DfHNo4.jpg', '[email&#160;protected]', NULL, 0, '', '\u81ea\u7531\u804c\u4e1a\u8005', b'1', b'1', NULL, '2021-01-14 15:25:59', NULL);  SET FOREIGN_KEY_CHECKS = 1; <\/code><\/pre>\n<p><strong>\u521b\u5efa maven \u5de5\u7a0b<\/strong><\/p>\n<h3>1.pom \u4f9d\u8d56<\/h3>\n<pre><code>&lt;parent&gt;     &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;     &lt;artifactId&gt;spring-boot-starter-parent&lt;\/artifactId&gt;     &lt;version&gt;2.3.8.RELEASE&lt;\/version&gt;     &lt;relativePath\/&gt; &lt;!-- lookup parent from repository --&gt; &lt;\/parent&gt; <\/code><\/pre>\n<pre><code>&lt;properties&gt;     &lt;maven.compiler.source&gt;8&lt;\/maven.compiler.source&gt;     &lt;maven.compiler.target&gt;8&lt;\/maven.compiler.target&gt;     &lt;project.build.sourceEncoding&gt;UTF-8&lt;\/project.build.sourceEncoding&gt;     &lt;project.reporting.outputEncoding&gt;UTF-8&lt;\/project.reporting.outputEncoding&gt;     &lt;mybatis-plus.version&gt;3.4.2&lt;\/mybatis-plus.version&gt;     &lt;fastjson.version&gt;1.2.75&lt;\/fastjson.version&gt;     &lt;hutool.version&gt;5.5.7&lt;\/hutool.version&gt;     &lt;jwt.version&gt;0.9.1&lt;\/jwt.version&gt;     &lt;emoji-java.version&gt;5.1.1&lt;\/emoji-java.version&gt; &lt;\/properties&gt;  &lt;dependencies&gt;     &lt;dependency&gt;         &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;         &lt;artifactId&gt;spring-boot-starter&lt;\/artifactId&gt;     &lt;\/dependency&gt;     &lt;!--web--&gt;     &lt;dependency&gt;         &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;         &lt;artifactId&gt;spring-boot-starter-web&lt;\/artifactId&gt;     &lt;\/dependency&gt;     &lt;!--lombok--&gt;     &lt;dependency&gt;         &lt;groupId&gt;org.projectlombok&lt;\/groupId&gt;         &lt;artifactId&gt;lombok&lt;\/artifactId&gt;         &lt;optional&gt;true&lt;\/optional&gt;     &lt;\/dependency&gt;     &lt;!--jjwt--&gt;     &lt;dependency&gt;         &lt;groupId&gt;io.jsonwebtoken&lt;\/groupId&gt;         &lt;artifactId&gt;jjwt&lt;\/artifactId&gt;         &lt;version&gt;${jwt.version}&lt;\/version&gt;     &lt;\/dependency&gt;     &lt;!--emoji-java \u8868\u60c5\u5305--&gt;     &lt;dependency&gt;         &lt;groupId&gt;com.vdurmont&lt;\/groupId&gt;         &lt;artifactId&gt;emoji-java&lt;\/artifactId&gt;         &lt;version&gt;${emoji-java.version}&lt;\/version&gt;     &lt;\/dependency&gt;     &lt;!-- lettuce pool \u7f13\u5b58\u8fde\u63a5\u6c60--&gt;     &lt;dependency&gt;         &lt;groupId&gt;org.apache.commons&lt;\/groupId&gt;         &lt;artifactId&gt;commons-pool2&lt;\/artifactId&gt;     &lt;\/dependency&gt;     &lt;!--HuTool--&gt;     &lt;dependency&gt;         &lt;groupId&gt;cn.hutool&lt;\/groupId&gt;         &lt;artifactId&gt;hutool-all&lt;\/artifactId&gt;         &lt;version&gt;${hutool.version}&lt;\/version&gt;     &lt;\/dependency&gt;     &lt;!--mysql--&gt;     &lt;dependency&gt;         &lt;groupId&gt;mysql&lt;\/groupId&gt;         &lt;artifactId&gt;mysql-connector-java&lt;\/artifactId&gt;         &lt;scope&gt;runtime&lt;\/scope&gt;     &lt;\/dependency&gt;     &lt;!--mybatis-plus--&gt;     &lt;dependency&gt;         &lt;groupId&gt;com.baomidou&lt;\/groupId&gt;         &lt;artifactId&gt;mybatis-plus-boot-starter&lt;\/artifactId&gt;         &lt;version&gt;${mybatis-plus.version}&lt;\/version&gt;     &lt;\/dependency&gt;     &lt;!--fastjson--&gt;     &lt;dependency&gt;         &lt;groupId&gt;com.alibaba&lt;\/groupId&gt;         &lt;artifactId&gt;fastjson&lt;\/artifactId&gt;         &lt;version&gt;${fastjson.version}&lt;\/version&gt;     &lt;\/dependency&gt;     &lt;!--yaml--&gt;     &lt;dependency&gt;         &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;         &lt;artifactId&gt;spring-boot-configuration-processor&lt;\/artifactId&gt;         &lt;optional&gt;true&lt;\/optional&gt;     &lt;\/dependency&gt;     &lt;!--bean validator--&gt;     &lt;dependency&gt;         &lt;groupId&gt;org.hibernate.validator&lt;\/groupId&gt;         &lt;artifactId&gt;hibernate-validator&lt;\/artifactId&gt;     &lt;\/dependency&gt;     &lt;dependency&gt;         &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;         &lt;artifactId&gt;spring-boot-starter-test&lt;\/artifactId&gt;         &lt;scope&gt;test&lt;\/scope&gt;         &lt;exclusions&gt;             &lt;exclusion&gt;                 &lt;groupId&gt;org.junit.vintage&lt;\/groupId&gt;                 &lt;artifactId&gt;junit-vintage-engine&lt;\/artifactId&gt;             &lt;\/exclusion&gt;         &lt;\/exclusions&gt;     &lt;\/dependency&gt; &lt;\/dependencies&gt; <\/code><\/pre>\n<h3>2.yam \u914d\u7f6e<\/h3>\n<pre><code># \u7aef\u53e3\u53f7 server:   port: 8081    # \u6570\u636e\u5e93 spring:   datasource:     driver-class-name: com.mysql.cj.jdbc.Driver     username: root     password: root     url: jdbc:mysql:\/\/127.0.0.1:3306\/nodepad_mblog?useUnicode=true&amp;characterEncoding=utf8&amp;autoReconnect=true&amp;serverTimezone=GMT%2B8     type: com.zaxxer.hikari.HikariDataSource  # sql \u65e5\u5fd7\u6253\u5370 mybatis-plus:   configuration:     log-impl: org.apache.ibatis.logging.stdout.StdOutImpl <\/code><\/pre>\n<h3>3.\u542f\u52a8\u7c7b<\/h3>\n<pre><code>\/\/ \u6211\u4eec\u8fd9\u91cc\u8fd8\u6ca1\u6709\u914d\u7f6e\u6570\u636e\u5e93\uff0cexclude = {DataSourceAutoConfiguration.class \u5c31\u662f\u542f\u52a8\u65f6\u4e0d\u52a0\u8f7d\u6570\u636e\u5e93 \/\/ @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) @Slf4j @SpringBootApplication public class BlogApplication {          public static void main(String[] args) {         ConfigurableApplicationContext context = SpringApplication.run(BlogApplication.class, args);         String port = context.getEnvironment().getProperty(\"server.port\");         log.info(\"http:\/\/localhost:\"+port);     } } <\/code><\/pre>\n<p><strong>\u542f\u52a8\u9879\u76ee\u6d4b\u8bd5\u6709\u6ca1\u6709\u62a5\u9519<\/strong><\/p>\n<h3>4.\u9879\u76ee\u8fd4\u56de\u548c\u9519\u8bef\u5904\u7406<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2021\/02\/20210224_6036102df0519.png\" alt=\"SpringBoot+Vue \u8c46\u5b9d\u793e\u533a\u524d\u540e\u7aef\u5206\u79bb\u9879\u76ee\u624b\u628a\u624b\u5b9e\u6218\u7cfb\u5217\u6559\u7a0b 02---\u521b\u5efa\u540e\u7aef\u5de5\u7a0b\" \/><\/p>\n<h4>4.1api \u6570\u636e\u8fd4\u56de<\/h4>\n<h5>IErrorCode<\/h5>\n<pre><code>public interface IErrorCode {     \/**      * \u9519\u8bef\u7f16\u7801: -1 \u5931\u8d25;200 \u6210\u529f      *      * @return \u9519\u8bef\u7f16\u7801      *\/     Integer getCode();      \/**      * \u9519\u8bef\u63cf\u8ff0      *      * @return \u9519\u8bef\u63cf\u8ff0      *\/     String getMessage(); } <\/code><\/pre>\n<h5>ApiErrorCode<\/h5>\n<pre><code>public enum ApiErrorCode implements IErrorCode {      \/**      * \u6210\u529f      *\/     SUCCESS(200, \"\u64cd\u4f5c\u6210\u529f\"),     \/**      * \u5931\u8d25      *\/     FAILED(-1, \"\u64cd\u4f5c\u5931\u8d25\"),     \/**      * \u672a\u767b\u5f55\uff0cToken \u8fc7\u671f      *\/     UNAUTHORIZED(401, \"\u6682\u672a\u767b\u5f55\u6216 token \u5df2\u7ecf\u8fc7\u671f\"),     \/**      * \u6743\u9650\u4e0d\u8db3      *\/     FORBIDDEN(403, \"\u6743\u9650\u4e0d\u8db3\"),     \/**      * \u53c2\u6570\u6821\u9a8c\u9519\u8bef      *\/     VALIDATE_FAILED(404, \"\u53c2\u6570\u68c0\u9a8c\u5931\u8d25\");      private final Integer code;     private final String message;      ApiErrorCode(int code, String message) {         this.code = code;         this.message = message;     }      @Override     public Integer getCode() {         return code;     }      @Override     public String getMessage() {         return message;     }      @Override     public String toString() {         return \"ApiErrorCode{\" +                 \"code=\" + code +                 \", message='\" +message + ''' +                 '}';     } } <\/code><\/pre>\n<h5>ApiResult<\/h5>\n<pre><code>import lombok.Data; import lombok.NoArgsConstructor;  import java.io.Serializable; import java.util.Optional;   @Data @NoArgsConstructor public class ApiResult&lt;T&gt; implements Serializable {      private static final long serialVersionUID = -4153430394359594346L;     \/**      * \u4e1a\u52a1\u72b6\u6001\u7801      *\/     private long code;     \/**      * \u7ed3\u679c\u96c6      *\/     private T data;     \/**      * \u63a5\u53e3\u63cf\u8ff0      *\/     private String message;      \/**      * \u5168\u53c2      *      * @param code    \u4e1a\u52a1\u72b6\u6001\u7801      * @param message \u63cf\u8ff0      * @param data    \u7ed3\u679c\u96c6      *\/     public ApiResult(long code, String message, T data) {         this.code = code;         this.message = message;         this.data = data;     }      public ApiResult(IErrorCode errorCode) {         errorCode = Optional.ofNullable(errorCode).orElse(ApiErrorCode.FAILED);         this.code = errorCode.getCode();         this.message = errorCode.getMessage();     }      \/**      * \u6210\u529f      *      * @param data \u7ed3\u679c\u96c6      * @return {code:200,message:\u64cd\u4f5c\u6210\u529f,data:\u81ea\u5b9a\u4e49}      *\/     public static &lt;T&gt; ApiResult&lt;T&gt; success() {         return new ApiResult&lt;T&gt;(ApiErrorCode.SUCCESS.getCode(), ApiErrorCode.SUCCESS.getMessage(), null);     }      \/**      * \u6210\u529f      *      * @param data \u7ed3\u679c\u96c6      * @return {code:200,message:\u64cd\u4f5c\u6210\u529f,data:\u81ea\u5b9a\u4e49}      *\/     public static &lt;T&gt; ApiResult&lt;T&gt; success(T data) {         return new ApiResult&lt;T&gt;(ApiErrorCode.SUCCESS.getCode(), ApiErrorCode.SUCCESS.getMessage(), data);     }      \/**      * \u6210\u529f      *      * @param data    \u7ed3\u679c\u96c6      * @param message \u81ea\u5b9a\u4e49\u63d0\u793a\u4fe1\u606f      * @return {code:200,message:\u81ea\u5b9a\u4e49,data:\u81ea\u5b9a\u4e49}      *\/     public static &lt;T&gt; ApiResult&lt;T&gt; success(T data, String message) {         return new ApiResult&lt;T&gt;(ApiErrorCode.SUCCESS.getCode(), message, data);     }      \/**      * \u5931\u8d25\u8fd4\u56de\u7ed3\u679c      *\/     public static &lt;T&gt; ApiResult&lt;T&gt; failed() {         return failed(ApiErrorCode.FAILED);     }      \/**      * \u5931\u8d25\u8fd4\u56de\u7ed3\u679c      *      * @param message \u63d0\u793a\u4fe1\u606f      * @return {code:\u679a\u4e3e ApiErrorCode \u53d6,message:\u81ea\u5b9a\u4e49,data:null}      *\/     public static &lt;T&gt; ApiResult&lt;T&gt; failed(String message) {         return new ApiResult&lt;T&gt;(ApiErrorCode.FAILED.getCode(), message, null);     }      \/**      * \u5931\u8d25      *      * @param errorCode \u9519\u8bef\u7801      * @return {code:\u5c01\u88c5\u63a5\u53e3\u53d6,message:\u5c01\u88c5\u63a5\u53e3\u53d6,data:null}      *\/     public static &lt;T&gt; ApiResult&lt;T&gt; failed(IErrorCode errorCode) {         return new ApiResult&lt;T&gt;(errorCode.getCode(), errorCode.getMessage(), null);     }      \/**      * \u5931\u8d25\u8fd4\u56de\u7ed3\u679c      *      * @param errorCode \u9519\u8bef\u7801      * @param message   \u9519\u8bef\u4fe1\u606f      * @return {code:\u679a\u4e3e ApiErrorCode \u53d6,message:\u81ea\u5b9a\u4e49,data:null}      *\/     public static &lt;T&gt; ApiResult&lt;T&gt; failed(IErrorCode errorCode, String message) {         return new ApiResult&lt;T&gt;(errorCode.getCode(), message, null);     }      \/**      * \u53c2\u6570\u9a8c\u8bc1\u5931\u8d25\u8fd4\u56de\u7ed3\u679c      *\/     public static &lt;T&gt; ApiResult&lt;T&gt; validateFailed() {         return failed(ApiErrorCode.VALIDATE_FAILED);     }      \/**      * \u53c2\u6570\u9a8c\u8bc1\u5931\u8d25\u8fd4\u56de\u7ed3\u679c      *      * @param message \u63d0\u793a\u4fe1\u606f      *\/     public static &lt;T&gt; ApiResult&lt;T&gt; validateFailed(String message) {         return new ApiResult&lt;T&gt;(ApiErrorCode.VALIDATE_FAILED.getCode(), message, null);     }      \/**      * \u672a\u767b\u5f55\u8fd4\u56de\u7ed3\u679c      *\/     public static &lt;T&gt; ApiResult&lt;T&gt; unauthorized(T data) {         return new ApiResult&lt;T&gt;(ApiErrorCode.UNAUTHORIZED.getCode(), ApiErrorCode.UNAUTHORIZED.getMessage(), data);     }      \/**      * \u672a\u6388\u6743\u8fd4\u56de\u7ed3\u679c      *\/     public static &lt;T&gt; ApiResult&lt;T&gt; forbidden(T data) {         return new ApiResult&lt;T&gt;(ApiErrorCode.FORBIDDEN.getCode(), ApiErrorCode.FORBIDDEN.getMessage(), data);     } } <\/code><\/pre>\n<h4>4.2 \u5168\u5c40\u5f02\u5e38<\/h4>\n<h5>ApiException<\/h5>\n<pre><code>public class ApiException extends RuntimeException {     private IErrorCode errorCode;      public ApiException(IErrorCode errorCode) {         super(errorCode.getMessage());         this.errorCode = errorCode;     }      public ApiException(String message) {         super(message);     }      public IErrorCode getErrorCode() {         return errorCode;     } } <\/code><\/pre>\n<h5>ApiAsserts<\/h5>\n<pre><code>public class ApiAsserts {     \/**      * \u629b\u5931\u8d25\u5f02\u5e38      *      * @param message \u8bf4\u660e      *\/     public static void fail(String message) {         throw new ApiException(message);     }      \/**      * \u629b\u5931\u8d25\u5f02\u5e38      *      * @param errorCode \u72b6\u6001\u7801      *\/     public static void fail(IErrorCode errorCode) {         throw new ApiException(errorCode);     } } <\/code><\/pre>\n<h5>GlobalExceptionHandler<\/h5>\n<pre><code>import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody;  import java.util.Map;  @ControllerAdvice public class GlobalExceptionHandler {     \/**      * \u6355\u83b7\u81ea\u5b9a\u4e49\u5f02\u5e38      *\/     @ResponseBody     @ExceptionHandler(value = ApiException.class)     public ApiResult&lt;Map&lt;String, Object&gt;&gt; handle(ApiException e) {         if (e.getErrorCode() != null) {             return ApiResult.failed(e.getErrorCode());         }         return ApiResult.failed(e.getMessage());     } } <\/code><\/pre>\n<h4><\/h4>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>1<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5324627\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : seven123 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u9519\uff0c\u611f\u8c22                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>SpringBoot+Vue \u8c46\u5b9d&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/352099"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=352099"}],"version-history":[{"count":1,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/352099\/revisions"}],"predecessor-version":[{"id":352102,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/352099\/revisions\/352102"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=352099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=352099"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=352099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}