Image Spring内容,如何在其他页面获取图像

Image Spring内容,如何在其他页面获取图像,image,spring-boot,file,image-processing,spring-content-community-project,Image,Spring Boot,File,Image Processing,Spring Content Community Project,我对Spring内容有问题。 我在建一家租车公司。用户有一个个人资料页面,上面有他拥有的汽车和一些关于这些汽车的信息,包括一张图片。然后,他可以添加一辆汽车,并应提供其图像。我决定在我的HSQLDB数据库中使用SpringContentJPA策略。 因此,我可以通过链接/data/{id}访问汽车图像。但我不知道如何在某个页面获取汽车图像。我应该在我的汽车实体中添加一个字段图像,还是在Spring内容中有一个现有的解决方案?此外,该车将显示在其他用户的汽车租赁页面上 汽车内容字段: CarIma

我对Spring内容有问题。 我在建一家租车公司。用户有一个个人资料页面,上面有他拥有的汽车和一些关于这些汽车的信息,包括一张图片。然后,他可以添加一辆汽车,并应提供其图像。我决定在我的HSQLDB数据库中使用SpringContentJPA策略。 因此,我可以通过链接/data/{id}访问汽车图像。但我不知道如何在某个页面获取汽车图像。我应该在我的汽车实体中添加一个字段图像,还是在Spring内容中有一个现有的解决方案?此外,该车将显示在其他用户的汽车租赁页面上

汽车内容字段:

CarImageStore:


看来你走对了方向

您已将您的
@ContentId
定义为实体上的
String
类型,但ContentStore上的
UUID
类型。它们应该是相同的,当使用Spring内容时,JPA应该是
String
类型

假设您使用的是Spring Content REST,并且它已启用(即,您要么依赖于
Spring Content REST启动程序
,要么导入了
org.springframework.Content.REST.RestConfiguration
),那么此时您需要做的就是在HTML中包含一个常规图像标记:


请求图像时,浏览器将发送一个基于图像的Accept标头,该标头应使请求与服务于内容的
StoreRestController.getContent
处理程序方法相匹配。应注意避免应用程序中的其他处理程序意外捕获这些请求。

Paul Warren,谢谢!现在它可以工作了,而且使用起来非常简单。刚刚把这个添加到我的页面。
@ContentId
private String contentId;

@ContentLength
private Long contentLength = 0L;

// if you have rest endpoints
@MimeType
private String mimeType = "image/png";
@StoreRestResource(path = "data")
@Repository
public interface CarImageStore extends ContentStore<Car, UUID> {
}
@Controller
@RequestMapping("/cars")
public class CarUIController {
    private final CarService service;
    private final CarImageStore store;

    public CarUIController(CarService service, CarImageStore store) {
        this.service = service;
        this.store = store;
    }

    @GetMapping
    public String getAll(Model model) {
        model.addAttribute("cars", service.getAll());
        return "cars";
    }

    @PostMapping
    public String create(Car car,
                         @RequestParam("file") MultipartFile file,
                         @AuthenticationPrincipal User authUser) {
        store.setContent(car, file.getResource());
        service.create(car, authUser.getId());
        return "redirect:/profile";
    }
}