#问题描述:给业务层织入切面后,业务层方法返回控制层后,返回值为null
#相关代码:
##controller:
@RequestMapping("/queryExample")
public Result queryExample(Long id) {
Example example = exampleService.findObject(id);
System.out.println("ExampleController***"+example);
return new Result(example);
}
##ExampleServiceImpl:
@Override
public Example findObject(Long id) {
Example example = exampleMapper.selectOne(id);
System.out.println("ExampleServiceImpl***"+example);
return example;
}
##ExampleAspect:
/**
* 切点方法
/
@Pointcut("execution( com.seanzhang.sys.service.*.*(..))")
public void pointCutDemo() {}
/**
* 环绕通知方法
* @param jp
*/
@Around("pointCutDemo()")
public void aroundDemo(ProceedingJoinPoint jp) {
try {
System.out.println("beforeAroundDemo()");
jp.proceed();
System.out.println("afterReturningAroundDemo()");
System.out.println("afterAroundDemo()");
} catch (Throwable e) {
System.out.println("afterThrowingAroundDemo()");
System.out.println("afterAroundDemo()");
e.printStackTrace();
}
}
#控制台
##没加切面控制台输出:
ExampleServiceImpl***Example [id=1, username=张三, password=123456]
ExampleController***Example [id=1, username=张三, password=123456]
##加完切面控制台输出:
beforeAroundDemo()
ExampleServiceImpl***Example [id=1, username=张三, password=123456]
afterReturningAroundDemo()
afterAroundDemo()
ExampleController***null
#可以看到,加完切面之后,对象从业务层返回控制层的时候竟然神奇的丢了,不知道有没有大神遇到过类似的问题?怎么解决的?谢谢!