Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring数据REST中/patch/request之后的调用逻辑_Java_Spring_Spring Data Rest - Fatal编程技术网

Java Spring数据REST中/patch/request之后的调用逻辑

Java Spring数据REST中/patch/request之后的调用逻辑,java,spring,spring-data-rest,Java,Spring,Spring Data Rest,我使用的是Spring数据REST。 如果有一个/补丁/请求一个特定实体,我会做某事(在这种情况下,发送一个带有保存对象的事件)。 由于Spring数据REST的原因,我没有/patch/method的代码,所以我尝试使用@RepositoryEventHandler和@handleftersave注释 @RepositoryEventHandler public class MyHandler { @HandleAfterSave public void handleAfterSave

我使用的是Spring数据REST。 如果有一个/补丁/请求一个特定实体,我会做某事(在这种情况下,发送一个带有保存对象的事件)。 由于Spring数据REST的原因,我没有/patch/method的代码,所以我尝试使用@RepositoryEventHandler和@handleftersave注释

@RepositoryEventHandler
public class MyHandler {
  @HandleAfterSave
  public void handleAfterSave(MyObj obj){
   //Do some after patch logic
  }
 }

它可以工作,但每次我保存MyObj实体时都会调用handleAfterSave。我只想在通过/path/request保存对象后调用我的逻辑。我怎样才能做到呢?也许通过方面?但是,因为我的项目中没有GetPatch方法,所以我不知道如何用方面来包装它。

实际上,事件处理程序与
MyObj
类绑定。因此,如果您真的想让它与
url/path
相关,您可以基于请求路径创建一个处理程序。还有另外一项工作似乎正在进行(我还没有测试过)

将另一个变量传递给方法签名以获取url路径,并基于此执行操作: 以下是一个例子:

@RepositoryEventHandler
public class MyHandler {
  @HandleAfterSave
  public void handleAfterSave(MyObj obj, HttpServletRequest request){
   
   String uri = request.getRequestURI();   
   if(uri.equals("expected uri")){
      //Do some after patch logic
   }
  }
 }
让我知道这是否有效