Boa tarde pessoal,
estou aprendendo o springMVC,tentei fazer uma lista de cadastro com fotos de canecas personalizadas.
Embora o produto esteja sendo cadastrado com sucesso, mostrando até mesmo o caminho do arquivo, ele acaba não retornando a imagem
Lista
Título
Descrição
Imagem
<c:forEach items="${produtos}" var="produtos"> <tr> <td>${produtos.nome}</td> <td>${produtos.descricao}</td> <td><c:url value='/${produtos.sumarioPath}' /></td> <td><img src="/${produtos.sumarioPath}"></td> </tr> </c:forEach> </table>
Sumario Path
String sumarioPath;public String getSumarioPath() {
return sumarioPath;
}public void setSumarioPath(String sumarioPath) {
this.sumarioPath = sumarioPath;
}
WebAPPConfiguration
@Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); registry.addResourceHandler("/WEB-INF/views/produtos/arquivos-sumario/**").addResourceLocations("/imagens/WEB-INF/views/produtos/imagens/"); } @Override public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { configurer.enable(); }
FileSaver!
@Component
public class FileSaver {@Autowired private HttpServletRequest request; public String write(String baseFolder, MultipartFile file) { try { String realPath = request.getServletContext().getRealPath("/"+ baseFolder); String path = realPath + "/" + file.getOriginalFilename(); file.transferTo(new File(path)); return baseFolder+ "/" + file.getOriginalFilename(); } catch (IllegalStateException | IOException e) { throw new RuntimeException(e); } }}
