完整application.yml(供参考)4.0.0 org.springframework.boot spring-boot-starter-parent 2.5.6 com.example demo 0.0.1-SNAPSHOT demo Demo project for Spring Boot 1.8 org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-jdbc mysql mysql-connector-java runtime com.alibaba druid 1.1.21 org.ssssssss magic-api-spring-boot-starter 1.7.1 io.springfox springfox-swagger2 2.9.2 io.springfox springfox-swagger-ui 2.9.2 org.springframework.boot spring-boot-devtools runtime true org.projectlombok lombok true org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-maven-plugin org.projectlombok lombok
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; ; -- -- Dumping data for table `user` -- LOCK TABLES `user` WRITE; ; INSERT INTO `user` VALUES (1,'小红','123','银河系红星','启用'),(2,'小橙','456','银河系橙星','启用'),(3,'小黄','789','银河系黄星','启用'),(4,'小绿','963','银河系绿星','启用'),(5,'小蓝','852','银河系蓝星','启用'),(6,'小青','741','银河系青星','启用'),(7,'小紫','951','银河系紫星','禁用'),(10,'小七','963852','银河系银河星','禁用'); ; UNLOCK TABLES; -- -- Table structure for table `user_magic` -- DROP TABLE IF EXISTS `user_magic`; ; ; 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; ; -- -- Dumping data for table `user_magic` -- LOCK TABLES `user_magic` WRITE; ; INSERT INTO `user_magic` VALUES (1,'若有诗词藏于心,岁月从不败美人'),(2,'最是人间留不住,朱颜辞镜花辞树'),(3,'醉后不知天在水,满船清梦压星河'),(4,'明月松间照,清泉石上流'),(5,'落花人独立,微雨燕双飞'),(6,'晚来天欲雪,能饮一杯无'),(7,'我自倾怀,君且随意'); ; UNLOCK TABLES;启动项目
可视化接口开发地址:http://localhost:8080/magic/web/index.html
地址中的/magic/web对应配置文件magic-api:web: /magic/web
swagger地址:http://localhost:8080/swagger-ui.html



