不管是MVC框架还是DAO框架,在业务场景中能够通用的个人觉得AOP是一个重点,看是不是可以合理使用,其他的框架都是基础框架
==================================
第一个AOP学习,对其类进行增强。
import java.util.Map;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
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.yyb.service.IAuthService;
import com.yyb.ws.SecurityMannager;
@Component
@Aspect
public class AuthServiceImpl implements IAuthService {
@Autowired
private SecurityMannager securityMannager;
//@After(value="pointRegister(map)",argNames="map")
@After(value="execution(* com.yyb.service.impl.UserServiceImpl.register(..)) && args(map)",argNames="map")
public void authOther(Map<String,String> map) {
System.out.println("AuthServiceImpl.authOther(map=" + map + ") in authOther ");
}
@Pointcut(value="execution(* com.yyb.service.impl.UserServiceImpl.login(..)) && args(cfg,other)",argNames="cfg,other")
public void pointAuth(String cfg,String other){}
//@Before(value="pointAuth(cfg,other)",argNames="cfg,other")
@Before(value="execution(* com.yyb.service.impl.UserServiceImpl.login(..)) && args(cfg,other)",argNames="cfg,other")
@Override
public void auth(String cfg,String other) {
securityMannager.doCheck(cfg + "-" + other );
System.out.println("AuthServiceImpl.auth(cfg=" + cfg + ",other=" + other + ") in auth ");
}
}
import java.util.Map;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import com.yyb.service.IUserService;
@Component
public class UserServiceImpl implements IUserService {
@Override
public void login(String name,String pass) {
System.out.println("UserServiceImpl.login() in login......");
}
@Override
public void register(Map<String,String> map) {
System.out.println("UserServiceImpl.register() in register......");
}
@Override
public void findUserByParams(String params) {
}
}