Spring Content 正是为此而设计的。
假设您使用的是 Spring Boot,那么您可以按如下方式添加 LOB 处理:
pom.xml
<dependency>
<groupId>com.github.paulcwarren</groupId>
<artifactId>spring-content-jpa-boot-starter</artifactId>
<version>0.0.11</version>
</dependency>
<dependency>
<groupId>com.github.paulcwarren</groupId>
<artifactId>spring-content-rest-boot-starter</artifactId>
<version>0.0.11</version>
</dependency>
添加商店:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@StoreRestResource(path="resourceContent")
public interface ResourceContentStore extends ContentStore<Resource,String> {}
}
将内容与您的实体实体相关联:
@Entity
public class Resource {
private String name;
@ContentId
private String contentId;
@ContentLength
private long contentLength = 0L;
@MimeType
private String mimeType = "text/plain";
}
这就是您所需要的。当您的应用程序启动时,Spring Content 将看到 Spring Content JPA/REST 模块上的依赖关系,它将为 JPA 注入 ResourceContentStore 存储的实现以及支持该映射的控制器(/resourceContent)的实现GET、POST、PUT 和 DELETE 请求到底层 Store 接口。 REST 端点将在下面可用。
即
curl -X PUT /resourceContent/{resourceId} 将创建或更新资源的内容
curl -X GET /resourceContent/{resourceId} 将获取资源的内容
curl -X DELETE /resourceContent/{resourceId}会删除资源内容
有一些入门指南here。他们将 Spring Content 用于文件系统,但模块是可互换的。 JPA 参考指南是here。还有教程视频here。
HTH