Java SpringBoot学习笔记 47 Swagger介绍及集成
来自B站【狂神说Java】SpringBoot最新教程IDEA版通俗易懂
1. Swagger 介绍
API工具,可以生成在线API文档,还可以测试接口
2. 新建项目
2.1

2.2 导入依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
2.3 增加注解 @EnableWebMvc
package com.example.swagger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@SpringBootApplication
@EnableWebMvc
public class SwaggerDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SwaggerDemoApplication.class, args);
}
}
2.3 编写一个 hello 工程
package com.example.swagger.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@RestController
@Api("HelloController")
public class HelloController {
@ApiOperation("hello")
@RequestMapping("/hello")
public String hello() {
return "hello";
}
}

浙公网安备 33010602011771号