swagger的使用

swagger的主要作用是:生成一个对功能进行测试的接口,开发者不用写前端页面就可以对后台的功能进行测试

1.添加依赖

 

 

2.添加配置文件

 新建一个config包

添加两个配置文件Swagger2.java和WebConfig.java

代码截图如下:

package com.braup.apps.poll.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**").allowedOrigins("*").allowedMethods("GET","POST","PUT","OPTIONS","DELETE","PATCH").allowCredentials(true).maxAge(3600);
    }
    
}

3.然后在浏览器访问http://localhost:8080/swagger-ui.html

就可以测试自己写的Controll了(前提是你写好了controller)