java.nio.file.nosuchfileexception:c:\ users \ pc \ desktop \ desktop \
我正在尝试将PNG文件分配给数据库中的所有产品,Spring Boot不识别我分配了我分配的值“ unknown.png”的文件或
每个产品的photOname属性,即文件名与此值相同,确实是一个PNG文件,我尝试更改路径的格式,然后尝试将toString()添加到路径上,但是当我打开Localhost:8000/时,我会得到相同的例外。光产物/1应该显示图像而不是
RestController如下:
@RestController
public class CatalogueRestController {
@Autowired
private ProductRepository productRepository;
@GetMapping(path="/photoProduct/{id}",produces = MediaType.IMAGE_PNG_VALUE)
public byte[] getPhoto(@PathVariable("id") Long id) throws Exception{
Product p=productRepository.findById(id).get();
return Files.readAllBytes(Paths.get("C:/Users/PC/Desktop/info1/ecom/products/unknown.png"));
}
}
谢谢
I'm trying to assign a png file to all the products in my database, Spring boot doesn't recognize either the path or the file
I've assigned the value "unknown.png" to the photoName attribute of every Product, the filename is the same as this value and it is indeed a PNG file, I tried to change the format of the path, and I tried to add a ToString() to the path, but I get the same exception when I open localhost:8000/photoProduct/1 when it should display the image instead
The RestController is as follows:
@RestController
public class CatalogueRestController {
@Autowired
private ProductRepository productRepository;
@GetMapping(path="/photoProduct/{id}",produces = MediaType.IMAGE_PNG_VALUE)
public byte[] getPhoto(@PathVariable("id") Long id) throws Exception{
Product p=productRepository.findById(id).get();
return Files.readAllBytes(Paths.get("C:/Users/PC/Desktop/info1/ecom/products/unknown.png"));
}
}
Thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经用
\\\
而不是/
进行了测试。I have tested with
\\\
instead of/
and it works.