Use Spring AOP for permission verification, springaop
Before using Spring AOP, you must first introduce the corresponding package
<dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.8.10</version></dependency><dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.8.10</version></dependency>
Then create the partition class
1 package com. homework. filter; 2 3 import org. aspectj. lang. proceedingJoinPoint; 4 import org. aspectj. lang. annotation. around; 5 import org. aspectj. lang. annotation. aspect; 6 import org. aspectj. lang. annotation. before; 7 import org. springframework. stereotype. component; 8 9/** 10 * Created by ytt on April /1/11. 11 */12 13 @ Aspect14 @ Component15 public class LoginCheckAspect {16 17 @ Around (value = "@ annotation (org. springframework. web. bind. annotation. requestMapping) ") 18 public Object checkUser (ProceedingJoinPoint pjp) throws Throwable {19 20 // obtain parameter 21 Object [] args = pjp. getArgs (); 22 System. out. println ("before entering the method"); 23 // allow 24 Object proceed = pjp. proceed (); 25 System. out. println ("after method execution"); 26 return proceed; 27} 28 29 @ Before ("execution (* com. homework. controller .. *. *(..)) ") 30 public void before () {31 System. out. println ("executed before method execution"); 32} 33}
In this way, the interception can be completed.