SpringBoot uses AOP to intercept the JSON of the request to obtain object parameters
for example
Entity class:
public class Company {
private Integer id;
private String companyName;
private Integer companyState;
public Company(Integer id, String companyName, Integer companyState) {
this.id = id;
this.companyName = companyName;
this.companyState = companyState;
}
public Company() {
super();
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public Integer getCompanyState() {
return companyState;
}
public void setCompanyState(Integer companyState) {
this.companyState = companyState;
}
}
Action class:
@RestController
@RequestMapping("company")
public class CompanyAction {
@RequestMapping(value="updateone",method=RequestMethod.POST)
public ReturnJSON<List<Company>> updateOne(@RequestBody Company company_param){
System.out.println("action");
return new ReturnJSON<List<Company>>(null);
}
}
Aop class:
@Aspect
@Component
public class LogAspect {
@Pointcut("execution(public * com.action.*.*(..))")
public void webLog(){}
@Around("webLog()")
public Object arround(ProceedingJoinPoint pjp) {
System.out.println("start.....");
try {
System.out.println("ARGS : " + Arrays.toString(pjp.getArgs()));
Object o = pjp.proceed();
System.out.println("proceed :" + o);
return o;
} catch (Throwable e) {
e.printStackTrace();
return null;
}
}
}
when I make a request, the console says something like this:
start.....
ARGS : [com.entity.Company@38250ab4]
action
proceed : com.entity4action.ReturnJSON@7a6f374c
my parameter to send the request is a JSON, and then let SpringBoot parse into the object Company through JSON, but I want to use AOP to record what the JSON received by the specific request is, how should I write it? Should you not intercept this class, but instead intercept a class in SpringBoot?