小编Mot*_*ine的帖子

通过Angular中的路由路径发送数据

无论如何使用router.navigate将数据作为参数发送?我的意思是,像这个例子,你可以看到路由有一个数据参数,但这样做它不起作用:

this.router.navigate(["heroes"], {some-data: "othrData"})
Run Code Online (Sandbox Code Playgroud)

因为某些数据不是有效参数.我怎样才能做到这一点?我不想用queryParams发送参数.

routing angular angular-router

130
推荐指数
5
解决办法
15万
查看次数

可以使用java中的反射替换方法引用

我在intellij中有这个代码:

 return collection.stream().anyMatch(annotation -> 
                        method.isAnnotationPresent(annotation));
Run Code Online (Sandbox Code Playgroud)

并且编译器告诉我"method.isAnnotationPresent(annotation)"可以用方法引用替换,我无法弄清楚如何做,因为它有一个参数.

有谁知道怎么做?

java reflection intellij-idea java-8 method-reference

8
推荐指数
1
解决办法
1万
查看次数

Spring 拦截不起作用

我知道这个问题已经被问过很多次了,但是没有一个能让我的代码工作。我可能做错了什么,但我不知道是什么。

我正在将 Spring Boot 与 AngularJS 结合使用,我想做的是预先处理所有请求。

这是我的代码:

控制器:

@RestController
@RequestMapping(value = { "/user" })
public class UserController {

    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public String getLanguage() {
        return "user";
    }
}
Run Code Online (Sandbox Code Playgroud)

拦截器:

@Component
public class RequestHandler extends HandlerInterceptorAdapter {

  @Override
  public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException {
      System.out.println("intercepted");
      return false;
  }
}
Run Code Online (Sandbox Code Playgroud)

网络配置:

@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {

  @Autowired
  HandlerInterceptor requestHandler;

  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(requestHandler);
  }
}
Run Code Online (Sandbox Code Playgroud)

我将其添加到 applicationContext.xml …

java spring interceptor angularjs

5
推荐指数
1
解决办法
8343
查看次数

AspectJ 建议在 Maven 多模块设置中不会触发

我正在尝试使用 Aspectj 进行 AOP,但我不知道为什么不执行我的方面,它只运行主类。这是我第一次这样做,所以我可能做错了什么。

这是我的代码:

方面:

@Aspect
public class YourAspect {

    @Pointcut("@annotation(yourAnnotationVariableName)")
    public void annotationPointCutDefinition(YourAnnotation yourAnnotationVariableName){
    }

    @Pointcut("execution(* *(..))")
    public void atExecution(){}

    @Around("annotationPointCutDefinition(yourAnnotationVariableName) && atExecution()")
    public Object aroundAdvice(ProceedingJoinPoint joinPoint, YourAnnotation yourAnnotationVariableName) throws Throwable {
        if(yourAnnotationVariableName.isRun()) {
            Object returnObject = null;

            try {
                System.out.println("aspects.YourAspect's aroundAdvice's body is now executed Before yourMethodAround is called.");
                returnObject = joinPoint.proceed();
            } catch (Throwable throwable) {
                throw throwable;
            } finally {
                System.out.println("aspects.YourAspect's aroundAdvice's body is now executed After yourMethodAround is called.");
            }
            return returnObject;
        }
        return …
Run Code Online (Sandbox Code Playgroud)

java aop aspectj maven aspectj-maven-plugin

5
推荐指数
2
解决办法
5200
查看次数