1.mybatisplus报Invalid bound statement (not found)错误的解决方法
解决方法:检查application.yml配置文件中mybais-plus的配置是否正确。
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
mybatis-plus:
# 禁止大写变小写时自动添加下划线
map-underscore-to-camel-case: false
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
mapper-locations: classpath:mybatis/*Mapper.xml
mybatis-plus 的配置要从spring中独立出来,否则会报错。
2.org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
解决方案: swagger2 和springboot的版本是否不兼容,降低swagger的版本,修改yml配置;
Spring Boot版本 | Swagger 版本 |
---|---|
2.6.5 | 3.0.0 |
修改application.yml 配置:
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
【swagger2】Spring Boot 配置swagger2_Ryan-Ren的博客-CSDN博客_springboot配置swagger2
3. javaweb下载文件时中文名称乱码,在网上查了很多资料,对文件名称进行了url编码处理,但是在swagger接口上下载文件后,文件名称还是编码后的乱码文件名,通过升级swagger版本由2升级为3后,问题解决。下载代码如下:
public ResponseEntity<byte[]> download(String fileName) {
ResponseEntity<byte[]> responseEntity = null;
InputStream in = null;
ByteArrayOutputStream out = null;
try {
in = new FileInputStream(fileName);
out = new ByteArrayOutputStream();
IOUtils.copy(in, out);
//封装返回值
byte[] bytes = out.toByteArray();
HttpHeaders headers = new HttpHeaders();
try {
File file = new File(fileName);
fileName = file.getName();
fileName = URLEncoder.encode(fileName, "UTF-8");
headers.add("Content-Disposition", "attachment;filename=" + fileName);
} catch (Exception e) {
e.printStackTrace();
}
headers.setContentLength(bytes.length);
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setAccessControlExposeHeaders(Arrays.asList("*"));
responseEntity = new ResponseEntity<byte[]>(bytes, headers, HttpStatus.OK);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return responseEntity;
}