我正在尝试实施Spring AOP @Before。 这是方法
String underTest = "some publication, issue no. 3";
String pattern = "(.*?), issue no. (\\d+)";
Matcher matcher = Pattern.compile(pattern).matcher(underTest);
boolean found = matcher.find();
if (found) {
log.info("something found");
String group1 = matcher.group(1);
log.info("group1: {}", group1);
String group2 = matcher.group(2);
log.info("group2: {}", group2);
}
这是我想要实现的两件事
答案 0 :(得分:1)
如果要修改控制流,则需要@Around
建议而不是@Before
建议。
@Around("execution(* com.dummy.pkg..*.*(..))")
public Response<Object> beforeServiceAspect(ProceedingJoinPoint joinPoint) throws Exception {
Object[] signatureArgs = joinPoint.getArgs();
String sessionId=(String) signatureArgs[0];
if(null==sessionId || sessionId.isEmpty() || !loginService.getUserInfo(sessionId))
{
Response.setStatusCode("401");
Response.setResultString("Unauthorized User");
return Response;
}
return joinPoint.proceed(args);
}