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 ...
随机推荐
- 为Dynamics CRM的Office附件注释定制个无需下载即可在线查看的功能
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复164或者20151021可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! 上一篇博客:为Dynamics ...
- jQuery Migrate 插件用法
jQuery Migrate是应用迁移辅助插件,是用于高级版本兼容低级版本辅助插件.例如jQuery版本用的是1.x,计划升级到3.x,就可以在页面删除1.x版本,换成3.x版本,如果有脚本错误,就引 ...
- ES 25 - Elasticsearch的分页查询及其深分页问题 (deep paging)
目录 1 分页查询方法 2 分页查询的deep paging问题 1 分页查询方法 在GET请求中拼接from和size参数 // 查询10条数据, 默认从第0条数据开始 GET book_shop/ ...
- Lnmp架构部署动态网站环境.2019-7-2-1.1
一.Mysql简介 Mysql数据库: 1.社区版 2.商业版 3.cluster集群 Mysql安装方式 1.编译安装 2.yum/rpm 3.二进制包,直接解压,无需编译 二.Mysql安装部署 ...
- 15.Java基础_初探对象
package pack1; public class Phone { //成员变量 String brand; int price; //成员方法 public void call(){ Syste ...
- 接口是用get还是post,如何选择?
为了保证信息安全性,注册.登录等操作通常都会使用POST请求,GET请求一般用来获取信息 GET与POST的区别可以参考下方链接 https://www.cnblogs.com/hyddd/archi ...
- selenium环境搭建:
环境搭建 基于python3和selenium3做自动化测试,俗话说:工欲善其事必先利其器:没有金刚钻就不揽那瓷器活,磨刀不误砍柴工,因此你必须会搭建基本的开发环境,掌握python基本的语法和一个I ...
- 开源规则引擎 drools
java语言开发的开源业务规则引擎 DROOLS(JBOSS RULES )具有一个易于访问企业策略.易于调整以及易于管理的开源业务规则引擎,符合业内标准,速度快.效率高.业务分析师或审核人员可以利用 ...
- display Flex 盒子模型布局兼容Android UC
<!DOCTYPE html><html><head><meta charset="utf-8"><meta content= ...
- MMM的又一周计划[2019 7.1→2019.7.7]
发现今天是7.1然后又是星期一 来一发吧 本周目标: 1.二分图最佳匹配 2.网络流 3.HH的项链 4.洛谷rk前1000(目前1.1k) (upd:469) 5.AC260(35题,上周A了34, ...