SpringBoot快速开始magic-api(可视化接口开发工具)

导读:本篇文章讲解 SpringBoot快速开始magic-api(可视化接口开发工具),希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

新建项目

在这里插入图片描述
在这里插入图片描述

完整pom.xml(供参考)

<?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 https://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>2.5.6</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.21</version>
        </dependency>
        <!-- magic-api -->
        <dependency>
            <groupId>org.ssssssss</groupId>
            <artifactId>magic-api-spring-boot-starter</artifactId>
            <version>1.7.1</version>
        </dependency>
        <!-- swagger2 -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

完整application.yml(供参考)

server:
  port: 8080
magic-api:
  web: /magic/web
  resource:
    #配置文件存储位置。当以classpath开头时,为只读模式
#    location: F:/data/magic-api
    type: database # 配置接口资源存储位置,可选file、database、redis
    tableName: magic_api_file # 存储表名
    # 使用database、redis存储时的key前缀
    prefix: /db2020
    readonly: false # 是否是只读模式
  response: |- #配置JSON格式,格式为magic-script中的表达式
    {
      code: code,
      message: message,
      data,
      timestamp,
      requestTime,
      executeTime,
    }
  response-code-config:
    success: 200 #执行成功的code值
    invalid: 400 #参数验证未通过的code值
    exception: 500 #执行出现异常的code值
  # 分页配置
  page-config:

    size: size # 页大小的请求参数名称
    page: page # 页码的请求参数名称
    default-page: 1 # 未传页码时的默认页码
    default-size: 10 # 未传页大小时的默认页大小
    # 集成Swagger配置
  swagger-config:
    version: 1.0
    description: MagicAPI
    title: MagicAPI Swagger Docs
    name: MagicAPI
    location: /v2/api-docs/magic-api/swagger2.json
  auto-import-module: db  # 自动导入的模块
  auto-import-package: java.lang.*,java.util.* #自动导包
  allow-override: false #禁止覆盖应用接口
  sql-column-case: camel #启用驼峰命名转换
  support-cross-domain: true # 跨域支持,默认开启
  show-sql: true #配置打印SQL
  security-config:  # 安全配置
    username: admin # 登录用的用户名
    password: 123456 # 登录用的密码

spring:
  datasource:
    url: jdbc:mysql://192.168.***.***:1***/magic?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
    username: *****
    password: 12****
    type: com.alibaba.druid.pool.DruidDataSource
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
    time-zone: GMT+8
    serialization:
      write-dates-as-timestamps: false
  servlet:
    multipart:
      enabled: true
      max-file-size: 1MB
      max-request-size: 20MB
      file-size-threshold: 2KB

项目Application文件添加注解

@EnableSwagger2

数据库脚本

CREATE TABLE `magic_api_file` (
  `id` bigint(255) NOT NULL AUTO_INCREMENT,
  `file_path` varchar(255) DEFAULT NULL,
  `file_content` text,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4;
-----
CREATE TABLE `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) COLLATE utf8_bin DEFAULT NULL,
  `password` varchar(255) COLLATE utf8_bin DEFAULT NULL,
  `addr` varchar(500) COLLATE utf8_bin DEFAULT NULL,
  `status` varchar(500) COLLATE utf8_bin DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=988 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `user`
--

LOCK TABLES `user` WRITE;
/*!40000 ALTER TABLE `user` DISABLE KEYS */;
INSERT INTO `user` VALUES (1,'小红','123','银河系红星','启用'),(2,'小橙','456','银河系橙星','启用'),(3,'小黄','789','银河系黄星','启用'),(4,'小绿','963','银河系绿星','启用'),(5,'小蓝','852','银河系蓝星','启用'),(6,'小青','741','银河系青星','启用'),(7,'小紫','951','银河系紫星','禁用'),(10,'小七','963852','银河系银河星','禁用');
/*!40000 ALTER TABLE `user` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `user_magic`
--

DROP TABLE IF EXISTS `user_magic`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `user_magic` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `magic` varchar(255) COLLATE utf8_bin DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `user_magic`
--

LOCK TABLES `user_magic` WRITE;
/*!40000 ALTER TABLE `user_magic` DISABLE KEYS */;
INSERT INTO `user_magic` VALUES (1,'若有诗词藏于心,岁月从不败美人'),(2,'最是人间留不住,朱颜辞镜花辞树'),(3,'醉后不知天在水,满船清梦压星河'),(4,'明月松间照,清泉石上流'),(5,'落花人独立,微雨燕双飞'),(6,'晚来天欲雪,能饮一杯无'),(7,'我自倾怀,君且随意');
/*!40000 ALTER TABLE `user_magic` ENABLE KEYS */;
UNLOCK TABLES;

启动项目

可视化接口开发地址:http://localhost:8080/magic/web/index.html
地址中的/magic/web对应配置文件magic-api:web: /magic/web
在这里插入图片描述

swagger地址:http://localhost:8080/swagger-ui.html
在这里插入图片描述

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/11820.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!