package com.whc.noteserver.aop;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.whc.noteserver.entity.NoteBook;
import com.whc.noteserver.param.NoteBookParam;
import com.whc.noteserver.service.NoteBookService;
@Aspect
@Component
public class NoteBookAOP {
@Autowired
private NoteBookService noteBookService;
@Pointcut("execution (* com.whc.noteserver.service.NoteBookService.addNoteBook(..))")
private void pointCut() {
}
@Before("pointCut()")
public void before() {
System.out.println("before add");
}
@Around("pointCut()")
public Object around(ProceedingJoinPoint proceedingJoinPoint) {
Object obj=null;
System.out.println("around add before");
Object[] args=proceedingJoinPoint.getArgs();
NoteBookParam noteBookParam=new NoteBookParam();
noteBookParam.setUserid(((NoteBook)args[0]).getUserid());
int re=noteBookService.getCount(noteBookParam);
if(re<5) {
try {
obj=proceedingJoinPoint.proceed();
} catch (Throwable e) {
e.printStackTrace();
}
}else{
System.out.println("around add after return -1");
return -1;
}
System.out.println("around add after");
return obj;
}
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-5821.html