问题:图片不能回显项目中使用了JWT做请求拦截验证。使用IDEA运行SpringBoot项目,上传文件到制定的本地目录下,但是回显的时候不能显示。请求回显的路径被拦截的时候没有登录,不响应请求。但是如果设置不拦截,在资源映射的时候又不能进入到映射的方法中。上传图片没有问题,一下是映射图片的方法,应该这么解决?@Configuration
public class MyWebMvcConfigurer implements WebMvcConfigurer { @Value("${moregs-oss.project-name}")
private String project; @Value("${moregs-oss.root-path}")
private String rootPath; /**
* 自动转换时间格式
*
* @param registry date
*/
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addFormatter(new DateFormatter("yyyy-MM-dd HH:mm:ss"));
} /**
* 资源映射路径
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler(project + "/**").addResourceLocations(rootPath);
}
}这么感觉无解呢。。高手赐教啊
public class MyWebMvcConfigurer implements WebMvcConfigurer { @Value("${moregs-oss.project-name}")
private String project; @Value("${moregs-oss.root-path}")
private String rootPath; /**
* 自动转换时间格式
*
* @param registry date
*/
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addFormatter(new DateFormatter("yyyy-MM-dd HH:mm:ss"));
} /**
* 资源映射路径
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler(project + "/**").addResourceLocations(rootPath);
}
}这么感觉无解呢。。高手赐教啊
。排除了之后
@Configuration 这个类进不去
。排除了之后
@Configuration 这个类进不去那就在登录拦截那里把静态资源访问路径排除了
。排除了之后
@Configuration 这个类进不去那就在登录拦截那里把静态资源访问路径排除了不是一个拦截器吗?没有多个拦截器啊
使用的是spring-Security 所有的请求在一个拦截器中
/**
*
* @param headImg
* @param route
* headImg 是获取用户头像的路由, pushinfo 是获取推流地址的二维码的路由
* @param response
* @throws IOException
*/
@ResponseBody
@RequestMapping(value = "/showImage", method = RequestMethod.GET)
public void showImage(@RequestParam(value = "imgName") String imgName, @RequestParam(value = "route") String route, HttpServletResponse response) throws IOException {
response.setContentType("text/html; charset=UTF-8");
response.setContentType("image/jpeg");
String parentPath = FileUtils.getBaseFilePath() + "/" + route;
FileUtils.createParentPath(parentPath);
String fullFileName = parentPath + "/" + imgName;
logger.debug("showImage fullFileName is :{}", fullFileName);
FileInputStream fis = new FileInputStream(fullFileName);
OutputStream os = response.getOutputStream();
try {
int count = 0;
byte[] buffer = new byte[1024 * 1024];
while ((count = fis.read(buffer)) != -1) {
os.write(buffer, 0, count);
}
os.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (os != null) {
os.close();
}
if (fis != null) {
fis.close();
}
}
}