1、定义一个切面,使用AfterReturning通知,修改、删除、新增等成功后更新缓存

    a、修改时先改数据库数据,修改成功后再同步到缓存中、

    b、删除时先删除数据库数据,删除成功再清理缓存中的对应数据

    c、新增时先插入数据库,插入成功,再同步进入缓存

com.aspect.demo;

com.model.Company;
com.model.ExceptionCompany;
com.Cache.RedisCache;
org.aspectj.lang.JoinPoint;
org.aspectj.lang.annotation.*;
org.slf4j.Logger;
org.slf4j.LoggerFactory;
;
java.util.List;

ReceiveCacheManager {


    //缓存管理类用来获取缓存中的单位信息数据
    RedisCache ;

    setRedisCache(RedisCache redisCache) {
        .= redisCache;
    }

    Logger = LoggerFactory.(ReceiveCacheManager.);
    ()
    insertService() { }

    ()
    updateService() { }

    ()
    deleteService() { }
    ()
         insertCompany(JoinPoint joinPoint) {
             {
            //获取方法参数
                 Object[] args = joinPoint.getArgs();
                 (args != && args.> && args[].getClass() == Company.) {
                     Company company = (Company) args[];
                     (.exists()){
                         Object object = .get();
                         (object == ){}{
                             List list = (List) object;
                             ExceptionCompany exceptionCompany = ExceptionCompany();
                             exceptionCompany.setBusinessLicense(company.getBusinessLicense());
                             exceptionCompany.setCompanyName(company.getCompanyName());
                             exceptionCompany.setCompanyAddress(company.getCompanyAddress());
                             exceptionCompany.setLinkMan(company.getLinkMan());
                             exceptionCompany.setLinkTel(company.getLinkTel());
                             exceptionCompany.setOrganizationCode(company.getOrganizationCode());
                             exceptionCompany.setTaxRegistration(company.getTaxRegistration());
                             list.add(exceptionCompany);
                             .set(,list);
                         }
                     }
                 }
                 .info(+ (joinPoint.getTarget().getClass().getName() + + joinPoint.getSignature().getName() + ));
                }(Exception e) {
                 .error(, e.getMessage());
             }
         }

    (pointcut=)
    updateCompany(JoinPoint joinPoint) {
        {
//获取方法参数

            Object[] args = joinPoint.getArgs();
            (args != && args.> && args[].getClass() == Company.) {
                Company company = (Company) args[];
                (.exists()){
                    Object object = .get();
                    (object == ){}{
                        List list = (List) object;
                        (i= ;i 
  
//获取方法参数

            Object[] args = joinPoint.getArgs();
            (args != && args.> && args[].getClass() == Company.) {
                Company company = (Company) args[];
                (.exists()){
                    Object object = .get();
                    (object == ){ }{
                        List list = (List) object;
                        (i= ;i来开启注解风格的@AspectJ支持-->