SpringBoot+Swagger整合
0.引言及注意事项
Swagger是一个接口文档工具,依照Swagger可以0配置开发接口。不过要注意,Swagger是基于SpringBoot1.47版本开发的,而SpringBoot现在基本都是是2+。
如果要选用restful支持,只能将SpringBoot退出到1+版本。
1.maven引入
<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>
2.Swagger配置文档
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class swaggerConfig {
@Bean
Docket docket(){
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.apiInfo(new ApiInfoBuilder().description("项目").build());
}
}
3.接口配置
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.just.computer.mathproject.Entity.Advertisement;
import org.just.computer.mathproject.Service.AdvertisementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@Api(tags ="广告")
@RequestMapping("/Advertisement/")
public class AdvertisementController {
@Autowired
AdvertisementService advertisementService;
@ApiOperation(value ="获得所有广告")
@GetMapping("/getAllAdvertisement")
public List<Advertisement> getAllAdvertisement(){
return advertisementService.getAllAdvertisement();
}
@ApiOperation(value = "添加广告")
@GetMapping("/addAdvertisement")
public Boolean getAllAdvertisement(@RequestParam String img, @RequestParam String href){
try {
advertisementService.addAdvertisement(img,href);
return true;
}catch (Exception e){
return false;
}
}
@ApiOperation(value = "删除广告")
@GetMapping("/deleteAdvertisement")
public Boolean deleteAdvertisementById(Integer id){
try{
advertisementService.deleteAdvertisementById(id);
return true;
}catch (Exception e){
return false;
}
}
}
本地运行后访问这里即可访问
或者到ip:端口/swagger-ui.html
运行结果如下
SpringBoot+Swagger整合的更多相关文章
- SpringBoot+Swagger整合API
SpringBoot+Swagger整合API Swagger:整合规范的api,有界面的操作,测试 1.在pom.xml加入swagger依赖 <!--整合Swagger2配置类--> ...
- springboot swagger 整合
Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务. 文件的方法,参数和模型紧密集成到服务器端的代码,允许API来始终保持同步. 作用: 1. ...
- SpringBoot+Swagger2 整合
SpringBoot+Swagger2四步整合 第一步:添加相关依赖 <parent> <groupId>org.springframework.boot</groupI ...
- springboot+jpa+mysql+swagger整合
Springboot+jpa+MySQL+swagger整合 创建一个springboot web项目 <dependencies> <dependency> < ...
- SpringBoot与Swagger整合
1 SpringBoot与Swagger整合https://blog.csdn.net/jamieblue1/article/details/99847744 2 Swagger详解(SpringBo ...
- springboot+swagger接口文档企业实践(上)
目录 1.引言 2.swagger简介 2.1 swagger 介绍 2.2 springfox.swagger与springboot 3. 使用springboot+swagger构建接口文档 3. ...
- SpringBoot 同时整合thymeleaf html、vue html和jsp
问题描述 SpringBoot如何同时访问html和jsp SpringBoot访问html页面可以,访问jsp页面报错 SpringBoot如何同时整合thymeleaf html.vue html ...
- SpringBoot+AOP整合
SpringBoot+AOP整合 https://blog.csdn.net/lmb55/article/details/82470388 https://www.cnblogs.com/onlyma ...
- SpringBoot+Redis整合
SpringBoot+Redis整合 1.在pom.xml添加Redis依赖 <!--整合Redis--> <dependency> <groupId>org.sp ...
随机推荐
- 表单_HTML
HTML表单_输入元素 大多数情况被用到的表单标签是输入标签 输入类型是由类型属性(type)定义的. 表单中的单选按钮可以设置以下几个属性:value.name.checked value:提交数据 ...
- GBT22239-2008-等保1.0三级要求
第三级基本要求 7.1 技术要求 7.1.1 物理安全 7.1.1.1 物理位置的选择(G3) 本项要求包括: a) 机房和办公场地应选择在具有防震.防风和防雨等能力的建筑内: b) 机房场地 ...
- netcore codefirst生成数据库命令
1.程序通过nuget安装包 Microsoft.EntityFrameworkCore.Design 2.生成添加脚本 add-migration InitialCreate -Context AL ...
- ubuntu 查看软件包中的内容 (已经安装)
在 使用 apt 进行安装软件的时候,我们要经常判断,软件安装了什么和安装到什么地方.这时候 我们要使用 dpkg -L 命令来进行查看: 同样 在 fedora 上可以使用 rpm -ql iper ...
- zz传统方法和深度学习结合的感知策略探索
今天分享下 Pony.ai 在感知探索的过程中,使用的传统方法和深度学习方法.传统方法不代表多传统,深度学习也不代表多深度.它们都有各自的优点,也都能解决各自的问题.我们希望发挥它们的优点,并且结合起 ...
- C# git忽略文件 (.gitignore )
# Visual Studio # User-specific files *.suo *.user *.userosscache *.sln.docstates # User-specific fi ...
- Forethought Future Cup - Elimination Round C 二分 + 交互(求树的直径)
https://codeforces.com/contest/1146/problem/C 题意 一颗大小为n的树,每次可以询问两个集合,返回两个集合中的点的最大距离,9次询问之内得出树的直径 题解 ...
- OpenCV Error: Unknown error code -10 (Raw image encoder error: Empty JPEG image (DNL not supported)) in throwOnEror 错误
出现上面这样的错误可以肯定是传了空指针导致的, 刚开始出现这样的问题, 并且是概率性的, 网上找了一遍都没找到解决方案, 然后自己一行一行代码注释, 发现还是会出现这样的问题, 当时就懵逼了, 我从打 ...
- CSS使用知识点
1.空白符 2.字符间距 3.省略号样式 4.水平垂直居中用法 5.CSS角标实现 空格符 1. 相当于键盘按下的空格,区别是 是可以累加的空格,键盘敲下的空格不会累加 2. ...
- 微服务 SpringCloud + docker
最近看到微服务很火,也是未来的趋势,所以就去学习下 好,接下来我们来认识下spring cloud.一.什么是spring cloud?它的中文官网这样说: 微服务架构集大成者,云计算最佳业务实践. ...