我想在spring data rest中使用以下功能。
如果我发送到集合资源端点,服务器应该检查对象是否存在。如果它已经存在,它应该执行与对项目资源执行merge-patch相同的功能。如果对象还不存在,它应该创建它。
这在spring data rest中是可以实现的吗?如果是,那么是如何实现的呢?
我使用的是SDR 2.4.1
当我执行时
http -v --auth admin:admin --json PATCH http://localhost:8080/api/messages/61?projection=withAccount readTimestamp="2015-12-15T11:32:06.380+0000"
我得到了以下异常:
java.lang.IllegalArgumentException: Target bean is not of type of the persistent entity!
at org.springframework
我已经使用Spring-Data-Rest按项目实现了。我正在尝试对表中的现有记录进行更新。但是,当我试图通过我的请求只发送几个字段而不是所有字段(存在于Entity类中)时,Spring-Data-Rest认为我发送的是null/空值。最后,当我去查看数据库时,我没有通过请求发送的字段将被null/null值覆盖。所以我的理解是,即使我没有发送这些值,spring data rest也会在实体类中看到它们,并将这些值作为null/empty发送。我这里的问题是,有没有办法在更新时禁用我没有通过请求发送的字段。感谢您的帮助。 更新:我使用的是PUT方法。在读完评论后,我把它改成了PATCH,
我使用的是Spring Data REST。在一个特定实体的一个/patch/请求的情况下,我会做一些事情(在这种情况下,用保存的对象发送一个事件)。由于Spring数据REST,我没有/patch/ method的代码,所以我尝试使用@RepositoryEventHandler和@HandleAfterSave注释 @RepositoryEventHandler
public class MyHandler {
@HandleAfterSave
public void handleAfterSave(MyObj obj){
//Do some after patch log
简短的版本是:如何使用Spring修补方法修补Postgres jsonb字段中包含的JSON对象?
下面是长篇版本,请考虑以下实体:
@Entity
@Table(name = "examples")
public class Example {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
private String jsonobject;
@JsonRawValue
public String getJsonobjec
公开REST资源的以下端点是相当常见的
@GET customers/ ==> list of customers
@POST customers/ ==> add a customer
@Get customers/:id ==> specific info of customer
@PUT customers/:id ==> override a customer
@PATCH customers/:id ==> update customer
Spring数据rest存储库很好地处理了这个问题。
但是,如果我想添加自定义端点,比如
@GET客户/最近的==&
我希望为下面的场景使用适当的方法来设计rest端点。
有一群人。每个组都有一个状态。管理员可以激活或禁用组。
我应该把我的终点设计成
PUT /groups/api/v1/groups/{group id}/status/activate
或
PATCH /groups/api/v1/groups/{group id}
with request body like
{action:activate|deactivate}
我是spring的新手,但对java来说并不陌生。
我想为所有的REST服务创建基类,这些服务将通过一些消息传递协议发送具有所选方法(POST,PUT,PACTCH)的请求的通知(当资源基本上改变时)
举个例子,如果我要创建接口
public interface RestService<T, I> {
T get(I id);
T create();
T patch(I id);
T put(I id);
}
我如何在spring RestController中使用它,并以某种方式用通知来装饰它?所有这些spring的@Autowire和配置文件都