首页 > 其他 > 详细

Swagger入门学习

时间:2021-09-01 13:36:30      阅读:30      评论:0      收藏:0      [点我收藏+]

Swagger简介

技术分享图片

入门使用

导入依赖

        <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>

写一个最简单的hellocontroller

package com.jie.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    @RequestMapping("/hello")
    public String hello(){
        return "hello";
    }
}

配置swagger

我们先简单使用

package com.jie.config;

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

@Configuration
@EnableSwagger2 //开启swagger2
public class SwaggerConfig {
}

运行项目
打开链接 http://localhost:8080/swagger-ui.html
前缀根据实际情况改
访问便可以发现swagger页面了
技术分享图片

Swagger入门学习

原文:https://www.cnblogs.com/OfflineBoy/p/15212496.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!