YAPI链接
1.添加项目
2.填写项目名称
3.添加接口
4.填接口名称,接口路径,有需要的可以填接口分类。
比如项目中需要两大模块,管理员与病患,且接口数目较多,就可以分类接口,以便更好管理。
这里的接口分类填了就行,不用后续其他操作。
5.最终效果
6.与后端连接,打开idea
package com.simplesin.config;
import com.simplesin.json.JacksonObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import java.util.List;
/**
* 配置类,注册web层相关组件
*/
@Configuration
@Slf4j
public class WebMvcConfiguration extends WebMvcConfigurationSupport {
/**
* 通过knife4j生成接口文档
* @return
*/
@Bean
public Docket docket() {
ApiInfo apiInfo = new ApiInfoBuilder()
.title("simplesin的项目接口文档")
.version("2.0")
.description("simplesin的项目接口文档")
.build();
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo)
.select()
.apis(RequestHandlerSelectors.basePackage("com.simplesin.controller"))
.paths(PathSelectors.any())
.build();
return docket;
}
}
7.在application.yml我配置的是8080
server:
port: 8080
spring:
profiles:
active: dev
main:
allow-circular-references: true
datasource:
druid:
driver-class-name: ${simplesin.datasource.driver-class-name}
url: jdbc:mysql://${simplesin.datasource.host}:${simplesin.datasource.port}/${simplesin.datasource.database}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
username: ${simplesin.datasource.username}
password: ${simplesin.datasource.password}
redis:
host: localhost
port: 6379
lettuce:
pool:
max-active: 10
max-idle: 10
min-idle: 1
time-between-eviction-runs: 10s
#mybatis:
# #mapper配置文件
#
# type-aliases-package: com.simplesin.entity
mybatis-plus:
type-aliases-package: com.simplesin.entity
global-config:
db-config:
id-type: auto
configuration:
#开启驼峰命名
map-underscore-to-camel-case: true
mapper-locations: classpath:mapper/*.xml
logging:
level:
com:
simplesin:
mapper: debug
service: info
controller: info
simplesin:
jwt:
# 设置jwt签名加密时使用的秘钥
admin-secret-key: itcast
# 设置jwt过期时间
admin-ttl: 7200000
# 设置前端传递过来的令牌名称
admin-token-name: token
8.输入localhost,电脑就会补全后面的信息
9.最终效果