来源还是因为前后端分离。简单理解就是写API的
使用SpringBoot创建一个项目 导入Pom
<!--Swagger依赖--> <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> <!--Swagger依赖结束-->新建一个配置类 后续的Swagger的配置都是在这个里面完成
package com.onlyk.swaggerdome.config; import org.springframework.context.annotation.Configuration; import springfox.documentation.swagger2.annotations.EnableSwagger2; /** * @author only老K 我为自己代言 * @create 2020-07-02 19:34 * @blogaddress https://blog.csdn.net/weixin_44255950 */ @Configuration //声明是配置类 @EnableSwagger2 //开启Swagger自动配置 public class swaggerConfig { }写个测试类
package com.onlyk.swaggerdome.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; /** * @author only老K 我为自己代言 * @create 2020-07-02 19:35 * @blogaddress https://blog.csdn.net/weixin_44255950 */ @Controller public class swaggerController { @RequestMapping("/hello") @ResponseBody public String helloSwagger(){ return "hello Swagger"; } }http://localhost:8081/swagger-ui.html
重启启动,后页面不一样了,加载了配置信息