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

网站的推广费用工地建筑劳务公司招工平台

网站的推广费用,工地建筑劳务公司招工平台,网页制作门户网站案例,做网站什么类型好文章目录 一、场景描述:swagger导出文件名称乱码二、乱码原因三、解决方法3.1、方法一、在浏览器中输入地址下载3.2、方法二、swagger升级为2.10.0及以上 四、可能遇到的问题4.1、DocumentationPluginsManager.java:152 一、场景描述:swagger导出文件名称…

文章目录

  • 一、场景描述:swagger导出文件名称乱码
  • 二、乱码原因
  • 三、解决方法
    • 3.1、方法一、在浏览器中输入地址下载
    • 3.2、方法二、swagger升级为2.10.0及以上
  • 四、可能遇到的问题
    • 4.1、DocumentationPluginsManager.java:152

一、场景描述:swagger导出文件名称乱码

场景描述:springboot项目集成swagger2.9.2后,下载文件时若文件名有中文则乱码。

(1)依赖如下

<!--swagger2-->
<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)下载文件乱码如下
在这里插入图片描述
(3)java代码如下

@Controller
@RequestMapping("/file")
public class FileController {@GetMapping("/export1")public void printSubmit1( HttpServletResponse response) throws Exception {//获取模板位置InputStream templateFileName = getClass().getResourceAsStream("/template/dataSourceDetailExport.xlsx");String fileName = "测试文件";List<List<String>> dataList = new ArrayList<>();for(int i=0;i<3;i++){List<String> data = new ArrayList<>();for(int j=1;j<10;j++){data.add(i+""+j);}dataList.add(data);}try {//对文件名进行编码,防止中文乱码fileName = URLEncoder.encode(fileName, "UTF-8");response.setContentType("application/vnd.ms-excel");response.setCharacterEncoding("utf8");response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".xlsx");response.setHeader("Pragma", "public");response.setHeader("Cache-Control", "no-store");response.addHeader("Cache-Control", "max-age=0");OutputStream os = response.getOutputStream();EasyExcel.write(os).withTemplate(templateFileName).sheet().doWrite(dataList);;} catch (IOException e) {throw new Exception("导出excel表格失败!", e);}}
}

二、乱码原因

这是由于sweagger2.9.2版本问题导致的,在swagger2.9.2中下载是乱码的,但是直接在浏览器中输入请求下载就是正常的。

三、解决方法

3.1、方法一、在浏览器中输入地址下载

在这里插入图片描述

3.2、方法二、swagger升级为2.10.0及以上

需要将swagger升级为2.10.0及以上
重点:需要swagger包含的spring-plugin-core包是2.0.0.RELEASE版本,swagger包含的spring-plugin-metadata包是2.0.0.RELEASE版本

(1)依赖如下

<!--swagger2-->
<dependency><groupId>io.springfox</groupId><artifactId>springfox-spring-webmvc</artifactId><version>2.10.0</version>
</dependency>
<dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>2.10.0</version>
</dependency>
<dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>2.10.0</version>
</dependency>

(2)swagger配置如下

package com.demo.config;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.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;import java.text.SimpleDateFormat;
import java.util.Date;@Configuration
@EnableSwagger2WebMvc
public class SwaggerConfig
{@Beanpublic Docket createRestApi() {return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage("com.demo")) //你自己的package.paths(PathSelectors.any()).build();}public ApiInfo apiInfo() {return new ApiInfoBuilder().title("小工具"+"\t"+new SimpleDateFormat("yyyy-MM-dd").format(new Date())).description("docker-compose").version("1.0").termsOfServiceUrl("").build();}
}

(3)下载结果如下图
在这里插入图片描述

四、可能遇到的问题

4.1、DocumentationPluginsManager.java:152

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

springfox.documentation.spring.web.plugins.DocumentationPluginsManager.createContextBuilder(DocumentationPluginsManager.java:152)

The following method did not exist:

org.springframework.plugin.core.PluginRegistry.getPluginFor(Ljava/lang/Object;Lorg/springframework/plugin/core/Plugin;)Lorg/springframework/plugin/core/Plugin;

The method's class, org.springframework.plugin.core.PluginRegistry, is available from the following locations:

jar:file:/D:/maven/MavenRepository/org/springframework/plugin/spring-plugin-core/2.0.0.RELEASE/spring-plugin-core-2.0.0.RELEASE.jar!/org/springframework/plugin/core/PluginRegistry.class

The class hierarchy was loaded from the following locations:

org.springframework.plugin.core.PluginRegistry: file:/D:/maven/MavenRepository/org/springframework/plugin/spring-plugin-core/2.0.0.RELEASE/spring-plugin-core-2.0.0.RELEASE.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.plugin.core.PluginRegistry

若遇到以上问题,则先在swagger中排除以下依赖,并手动引入以下版本的依赖

<dependency><artifactId>spring-plugin-core</artifactId><groupId>org.springframework.plugin</groupId><version>2.0.0.RELEASE</version>
</dependency>
<dependency><artifactId>spring-plugin-metadata</artifactId><groupId>org.springframework.plugin</groupId><version>2.0.0.RELEASE</version>
</dependency>

注意: spring-plugin-core-2.0.0.RELEASE版本需要与swagger2.10.0及以上版本配合使用。若swagger版本为2.9.2及以下,需要用低版本的spring-plugin-core-1.2.0.RELEASE版本

http://www.yayakq.cn/news/887883/

相关文章:

  • 怎麽做网站网站 备案 在哪
  • 石家庄智能网站建设wordpress翻译插件下载
  • 电影网站开发教程网站建设柚子网络科技
  • 塑钢模板价格一平方北京seo公司司
  • 行业网站建设深圳公司门户网站建设背景
  • 建设网站得目的wordpress多个主体功能合并
  • 南阳做网站优化哪个软件发视频可以赚钱
  • 网站被攻击的方法广州做网站信科建设
  • 临潼建设项目环境影响网站用wordpress付费网站
  • 佛山企业如何建网站在中国做国外网站
  • 做网站如何用代码把字体变大wordpress图片二级域名
  • 做安装系统网站有钱赚吗cpa推广联盟平台
  • 浅谈电子商务网站建设东莞市桥头镇网络工程公司
  • 网站如何后台管理橱柜网站源码
  • 安徽城乡建设厅网站证件动漫设计是什么
  • 滕州网站建wordpress目录介绍
  • 几大门户网站网站开发需要掌握哪些技术
  • dede网站不能够生成骑士cms怎么从别的网站采集信息
  • 上海专业网站建设公司排名如何整理做网站的素材
  • 网站建设信息在哪儿发布互联网技术包括哪些
  • 北京网站建设公司分享网站改版注意事项免费刷粉网站推广免费
  • 网站登记备案 个人做网站和推广找哪家好
  • 网站建设的电话回访wordpress cdn图片加速
  • 有哪些做红色旅游景点的网站网页模板dw
  • 微网站和网站同步像素成都高端网页设计公司
  • 网站常用的颜色体育设施 网站模版
  • 做网站f12的用处主播培训
  • 网站上线2年才做301百度和阿里哪个厉害做网站
  • 深圳企业做网站公司哪家好网络设计主要是干什么的
  • 域名备案用的网站建设方案哪里有建站代理加盟