日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

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

發布時間:2025/3/19 javascript 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SpringBoot+Swagger2.7.0实现汉化(2.8.0不行) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

場景

SpringBoot+Swagger2實現可視化API文檔流程:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/93616618

上面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查看效果

總結

以上是生活随笔為你收集整理的SpringBoot+Swagger2.7.0实现汉化(2.8.0不行)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。