当前位置: 首页 > news >正文

SpringBoot+Swagger2.7.0实现汉化(2.8.0不行)

场景

SpringBoot+Swagger2实现可视化API文档流程:

SpringBoot+Swagger2实现可视化API文档流程_swagger 可视化端口-CSDN博客

上面SpringBoot中使用swagger的效果

上面使用的是swagger2.8.0,且在线API是英文的。现在要将其进行汉化。

汉化效果

实现

首先打开springBoot项目的pom.xml文件,将swagger的版本修改为2.7.0

<!--swagger2--><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>2.7.0</version></dependency><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>2.7.0</version></dependency>

配置静态资源访问路径

找到springBoot项目的配置文件,这里是application-dev.yml

spring:profiles: devthymeleaf:mode: HTMLcache: falseprefix: classpath:/templates/suffix: .htmlencoding: UTF-8mvc:view:prefix: /templates/static-path-pattern: /static/**resources:static-locations: classpath:/META-INF/resources

将static-path-pattern与 static-locations进行配置,如果是properties配置文件

#配置静态资源访问
spring.mvc.static-path-pattern=/static/**
spring.resources.static-locations=classpath: META-INF/resources


 新建ui文件

在src/main/resources下新建META-INF目录,并在此目录下新建resources目录,然后在此

目录下新建swagger-ui.html

将以下代码复制进上面html中

<!DOCTYPE html>
<html>
<head><meta charset="UTF-8"><title>Swagger UI</title><link rel="icon" type="image/png" href="webjars/springfox-swagger-ui/images/favicon-32x32.png" sizes="32x32"/><link rel="icon" type="image/png" href="webjars/springfox-swagger-ui/images/favicon-16x16.png" sizes="16x16"/><link href='webjars/springfox-swagger-ui/css/typography.css' media='screen' rel='stylesheet' type='text/css'/><link href='webjars/springfox-swagger-ui/css/reset.css' media='screen' rel='stylesheet' type='text/css'/><link href='webjars/springfox-swagger-ui/css/screen.css' media='screen' rel='stylesheet' type='text/css'/><link href='webjars/springfox-swagger-ui/css/reset.css' media='print' rel='stylesheet' type='text/css'/><link href='webjars/springfox-swagger-ui/css/print.css' media='print' rel='stylesheet' type='text/css'/><script src='webjars/springfox-swagger-ui/lib/object-assign-pollyfill.js' type='text/javascript'></script><script src='webjars/springfox-swagger-ui/lib/jquery-1.8.0.min.js' type='text/javascript'></script><script src='webjars/springfox-swagger-ui/lib/jquery.slideto.min.js' type='text/javascript'></script><script src='webjars/springfox-swagger-ui/lib/jquery.wiggle.min.js' type='text/javascript'></script><script src='webjars/springfox-swagger-ui/lib/jquery.ba-bbq.min.js' type='text/javascript'></script><script src='webjars/springfox-swagger-ui/lib/handlebars-4.0.5.js' type='text/javascript'></script><script src='webjars/springfox-swagger-ui/lib/lodash.min.js' type='text/javascript'></script><script src='webjars/springfox-swagger-ui/lib/backbone-min.js' type='text/javascript'></script><script src='webjars/springfox-swagger-ui/swagger-ui.min.js' type='text/javascript'></script><script src='webjars/springfox-swagger-ui/lib/highlight.9.1.0.pack.js' type='text/javascript'></script><script src='webjars/springfox-swagger-ui/lib/highlight.9.1.0.pack_extended.js' type='text/javascript'></script><script src='webjars/springfox-swagger-ui/lib/jsoneditor.min.js' type='text/javascript'></script><script src='webjars/springfox-swagger-ui/lib/marked.js' type='text/javascript'></script><script src='webjars/springfox-swagger-ui/lib/swagger-oauth.js' type='text/javascript'></script><script src='webjars/springfox-swagger-ui/springfox.js' type='text/javascript'></script><!--国际化操作:选择中文版 --><script src='webjars/springfox-swagger-ui/lang/translator.js' type='text/javascript'></script><script src='webjars/springfox-swagger-ui/lang/zh-cn.js' type='text/javascript'></script></head><body class="swagger-section">
<div id='header'><div class="swagger-ui-wrap"><a id="logo" href="![](webjars/springfox-swagger-ui/images/logo_small.png)![](webjars/springfox-swagger-ui/images/logo_small.png)![](webjars/springfox-swagger-ui/images/logo_small.png)![](webjars/springfox-swagger-ui/images/logo_small.png)http://swagger.io">![](webjars/springfox-swagger-ui/images/logo_small.png)<span class="logo__title">swagger</span></a><form id='api_selector'><div class='input'><select id="select_baseUrl" name="select_baseUrl"></select></div><div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div><div id='auth_container'></div><div class='input'><a id="explore" class="header__btn" href="#" data-sw-translate>Explore</a></div></form></div>
</div><div id="message-bar" class="swagger-ui-wrap" data-sw-translate> </div>
<div id="swagger-ui-container" class="swagger-ui-wrap"></div>
</body>
</html>

重启项目,重新访问在线API查看效果

http://www.lryc.cn/news/465397.html

相关文章:

  • c++ 散列表
  • Windows通过netsh控制安全中心防火墙和网络保护策略
  • UML(Unified Modeling Language,统一建模语言)
  • 深⼊理解指针(2)
  • Ubuntu中MySQL远程登录设置
  • typescript 中封装一个 class 来解析接口响应数据
  • [LeetCode] 21. 合并两个有序链表
  • CTFHUB技能树之SQL——MySQL结构
  • Git小知识:合理的分支命名约定
  • Ubuntu如何显示pcl版本
  • wordcloud 字体报错
  • 使用Matplotlib绘制极轴散点图
  • Elasticsearch入门:增删改查详解与实用场景
  • 【AI论文精读6】SELF-RAG(23.10)附录
  • sql-labs靶场第十七关测试报告
  • 面试官:MySQL一次到底插入多少条数据合适啊?
  • WSL2 构建Ubuntu系统-轻量级AI运行环境
  • 什么是凸二次规划问题
  • 解决 Elasticsearch cluster_block_exception 错误的终极指南
  • QT sql驱动错误QMYSQL driver not loaded
  • 数据驱动,漫途能耗管理系统打造高效节能新生态!
  • PH47代码框架软件二次开发极简教程
  • SQL Server-导入和导出excel数据-注意事项
  • Linux系统:配置Apache支持CGI(Ubuntu)
  • qt 序列化和反序列化
  • java实现文件变动监听
  • Maven的使用
  • C++开发进阶1:C++编程命名规范
  • Android 图片相识度比较(pHash)
  • Gitlab 完全卸载–亲测可行