在用户使用Spring登录Java项目时,在标题部分显示mysql数据库中的用户图片

时间:2019-06-16 21:53:21

标签: java mysql spring-boot

//controller is to upload file(file,image) to mysql database on phpmyadmin

@RequestMapping(value="/download/dsLogo")
public void getImage(@RequestParam("file") String fileName, HttpServletResponse response) throws IOException{       

drivingSchoolService.findById(Integer.parseInt(fileName));
File file = new File(fileFolder1+fileName);

响应
etHeader("Content-Type", context.getMimeType(fileName));
response.setHeader("Content-Length", String.valueOf(file.length()));     
response.setHeaderresponse.setHeader("Content-Disposition", "inline; filename=\"" + file.getName() + "\"");
Files.copy(file.toPath(), response.getOutputStream());
}

header.jsp

<img src="${pageContext.request.contextPath}/file/download/dsLogo?file=${drivingSchool.dsLogo}"class="img-circle img-responsive pull-left" 
alt="User Image">

0 个答案:

没有答案