-1

我想在我的流程执行生命周期中将 spring 方面用于我的横切流程,例如之前或之后的处理程序。例如

在我想要执行我的处理程序的方法之前我想要什么,并且由于它的响应,我想要完成 myprocess 并返回自定义响应。

例如在停止条件下我应该抛出自定义异常以停止进程那个时候我如何处理我的返回响应,我想在客户端提供有意义的对象。最好的方法是什么?

@Before
MyHandler()
{

bool stop=checkvalue();
if(stop==false)
continue...
else
{
  //break all process
    and return custom response to client
  //throw exception but meaningfullresponse??
}

}
4

1 回答 1

0

Before我不会使用建议,而是使用Around建议来包装方法调用并checkValue()预先调用:

@Around("someJoinpoint")
public Object MyHandler(ProceedingJoinPoint pjp) {
    if (!checkvalue()) {
        return pjp.proceed();
    } else {
        return someCustomResponseToClient();
    }
}

更多关于Around建议的信息可以在Spring 文档中找到。

于 2019-05-15T07:57:03.897 回答