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

新建项目

SpringBoot快速开始magic-api(可视化接口开发工具)_第1张图片
SpringBoot快速开始magic-api(可视化接口开发工具)_第2张图片

完整pom.xml(供参考)


<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.0modelVersion>
    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>2.5.6version>
        <relativePath/> 
    parent>
    <groupId>com.examplegroupId>
    <artifactId>demoartifactId>
    <version>0.0.1-SNAPSHOTversion>
    <name>demoname>
    <description>Demo project for Spring Bootdescription>
    <properties>
        <java.version>1.8java.version>
    properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starterartifactId>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-jdbcartifactId>
        dependency>
        <dependency>
            <groupId>mysqlgroupId>
            <artifactId>mysql-connector-javaartifactId>
            <scope>runtimescope>
        dependency>
        <dependency>
            <groupId>com.alibabagroupId>
            <artifactId>druidartifactId>
            <version>1.1.21version>
        dependency>
        
        <dependency>
            <groupId>org.ssssssssgroupId>
            <artifactId>magic-api-spring-boot-starterartifactId>
            <version>1.7.1version>
        dependency>
        
        <dependency>
            <groupId>io.springfoxgroupId>
            <artifactId>springfox-swagger2artifactId>
            <version>2.9.2version>
        dependency>
        <dependency>
            <groupId>io.springfoxgroupId>
            <artifactId>springfox-swagger-uiartifactId>
            <version>2.9.2version>
        dependency>


        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-devtoolsartifactId>
            <scope>runtimescope>
            <optional>trueoptional>
        dependency>

        <dependency>
            <groupId>org.projectlombokgroupId>
            <artifactId>lombokartifactId>
            <optional>trueoptional>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
            <scope>testscope>
        dependency>
    dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombokgroupId>
                            <artifactId>lombokartifactId>
                        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
SpringBoot快速开始magic-api(可视化接口开发工具)_第3张图片

swagger地址:http://localhost:8080/swagger-ui.html
SpringBoot快速开始magic-api(可视化接口开发工具)_第4张图片

你可能感兴趣的:(springboot,spring,boot,java)