springboot配置swagger2

配置

pom添加坐标

		<dependency>
			<groupId>io.springfoxgroupId>
			<artifactId>springfox-swagger2artifactId>
			<version>2.9.2version>
		dependency>
		<dependency>
			<groupId>io.springfoxgroupId>
			<artifactId>springfox-swagger-uiartifactId>
			<version>2.9.2version>
		dependency>

添加Swagger配置类

Swaager不是springboot生态,所以需要新建配置类
配置类可以实现代码控制开启关闭、扫描包等功能,可以自行搜索
这里的配置类是空的,但是能用来启动Swaager

springboot配置swagger2_第1张图片

package com.greentran.origin.config;


import org.springframework.context.annotation.Configuration;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@Configuration
@EnableSwagger2
public class SwaggerConfig {

}

测试效果

新建Controller类

springboot配置swagger2_第2张图片

package com.greentran.origin.controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Value;

@Validated
@RestController
@RequestMapping("/user")
public class userController {


    @PostMapping(value = "login")
    public String login() {
        return "登录返回值";
    }
}

访问Swagger

项目地址+端口+swagger-ui.html
例如:http://localhost:8080/origin/swagger-ui.html

你可能感兴趣的:(java,spring,boot,java,spring,Swagger)