当前位置: 首页 > wzjs >正文

寻找南京帮助做网站的单位线上推广有哪些平台效果好

寻找南京帮助做网站的单位,线上推广有哪些平台效果好,web前端是程序员吗,网站模版如何去除title版权信息代理 静态代理基于继承实现动态代理是基于接口实现 业务层每次实现转账都需要执行,可以把他们拿出来当成一个切面,自己写出一个代理类,让业务层只执行业务的逻辑,重复的代码代理类来完成,然后调用代理类来执行。 代理类…

代理

  • 静态代理基于继承实现
  • 动态代理是基于接口实现
业务层每次实现转账都需要执行,可以把他们拿出来当成一个切面,自己写出一个代理类,让业务层只执行业务的逻辑,重复的代码代理类来完成,然后调用代理类来执行。
代理类
package com.qcby.utils;import com.qcby.service.AccountService;import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;//传入目标对象,生成该对象的代理对象,返回。对目标对象的方法进行增强
public class ProxyUtils {//获取代理对象,返回,增强目标对象的方法public static Object getProxy(final AccountService accountService){//使用jdk动态dialing生成代理对象Object proxy = Proxy.newProxyInstance(ProxyUtils.class.getClassLoader(), accountService.getClass().getInterfaces(), new InvocationHandler() {//调用代理对象的方法,invoke方法就会去执行public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {//目标对象的方法Object result = null;try {//开启事务TxUtils.startTransaction();//目标对象的方法进行增强,作为结果返回result = method.invoke(accountService,args);//事务提交TxUtils.commit();}catch (Exception e){e.printStackTrace();//事务回滚TxUtils.rollback();}finally {//资源关闭TxUtils.close();}return result;}});return proxy;}
}
测试
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class Demo2 {@Autowiredprivate AccountService accountService;@Testpublic void run1(){Account account1 = new Account();account1.setName("aaa");Account account2 = new Account();account2.setName("bbb");//创建代理对象AccountService proxy = (AccountService) ProxyUtils.getProxy(accountService);proxy.saveAll(account1,account2);}
}

     AOP

    配置文件形式:(IOC也是用的配置文件形式)
    配置文件
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsd"><!--将目标类配置到spring中--><bean id="userService" class="com.qcby.demo1.UserServiceImpl"/><!--将切面类配置到spring中--><bean id="myXmlAspect" class="com.qcby.demo1.MyXmlAspect"/><!--配置AOP的增强--><aop:config><!--配置切面 = 通知+切入点组成--><aop:aspect ref="myXmlAspect"><!--通用写法--><!--<aop:before method="log" pointcut="execution(public * com.qcby.*.*ServiceImpl.*(..))"/>--><!--前置通知:无论方法成功与否都执行--><!--<aop:before method="log" pointcut="execution(public void com.qcby.demo1.UserServiceImpl.save())"/>--><!--最终通知:失败成功都执行--><!--<aop:after method="log" pointcut="execution(public void com.qcby.demo1.UserServiceImpl.save())"/>--><!--后置通知:方法成功执行之后执行--><!--<aop:after-returning method="log" pointcut="execution(public * com.qcby.*.*ServiceImpl.*(..))"/>--><!--异常通知:有异常才执行--><!--<aop:after-throwing method="log" pointcut="execution(public void com.qcby.demo1.UserServiceImpl.save())"/>--><!--环绕通知:目标方法执行前后都执行  执行方法成功与否对执行前的增强不影响(方法执行不成功也执行前置的)--><aop:around method="aroundLog" pointcut="execution(public * com.qcby.demo1.*ServiceImpl.*(..))"/></aop:aspect></aop:config></beans>
    切面类
    package com.qcby.demo1;import org.aspectj.lang.ProceedingJoinPoint;/*定义切面类 = 切入点(表达式)+通知*/
    //在配置文件里配置成切面类=增强的方法(通知)+需要增强的方法(切入点)
    public class MyXmlAspect {/*通知*/public void log(){//发送手机短信//发送邮件、记录日志、事务管理System.out.println("增强的方法执行了....");}public void log1(){//发送手机短信//发送邮件、记录日志、事务管理System.out.println("前置增强的方法执行了....");}public void log2(){//发送手机短信//发送邮件、记录日志、事务管理System.out.println("后置增强的方法执行了....");}/*环绕通知*/public void aroundLog(ProceedingJoinPoint proceedingJoinPoint){try {log1();proceedingJoinPoint.proceed();log2();} catch (Throwable throwable) {throwable.printStackTrace();}}
    }
    测试类
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations = "classpath:applicationContext.xml")
    public class Demo1 {@Autowiredprivate UserService userService;/*测试*/@Testpublic void run1(){userService.save();}
    }
    半注解方式
    切面类=通知+切入点(现在的切面类已经在通知上添加了切入点)
    package com.qcby.demo2;import org.aspectj.lang.ProceedingJoinPoint;
    import org.aspectj.lang.annotation.*;
    import org.springframework.stereotype.Component;@Component  // 把该类交给 IOC 去管理
    @Aspect // 声明是切面类 == <aop:aspect ref="myXmlAspect">
    public class MyAnnoAspect {//@Before(value = "execution(public * com.qcby.*.*ServiceImpl.*(..))")public void log1(){System.out.println("前置通知增强的方法执行...");}//@AfterReturning(value = "execution(public * com.qcby.*.*ServiceImpl.*(..))")public void log2(){System.out.println("后置通知增强的方法执行...");}//@After(value = "execution(public * com.qcby.*.*ServiceImpl.*(..))")public void log3(){System.out.println("最终通知增强的方法执行...");}//@AfterThrowing(value = "execution(public * com.qcby.*.*ServiceImpl.*(..))")public void log4(){System.out.println("异常通知增强的方法执行...");}@Around(value = "execution(public * com.qcby.*.*ServiceImpl.*(..))")public void log5(ProceedingJoinPoint proceedingJoinPoint){try {log1();proceedingJoinPoint.proceed();log2();} catch (Throwable throwable) {throwable.printStackTrace();}}
    }
    配置文件
    <!--配置文件中开启自动代理-->
    <aop:aspectj-autoproxy/>
    <!--开启注解扫描-->
    <context:component-scan base-package="com.qcby" />
    测试类
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations = "classpath:applicationContext.xml")
    public class Demo2 {@Autowiredprivate AccountService accountService;@Testpublic void run1(){accountService.save();}
    }
    纯注解形式
    配置类
    @Configuration  // 配置类
    @ComponentScan(value = "com.qcby")  // 扫描包
    @EnableAspectJAutoProxy  // 开启自动代理 == <aop:aspectj-autoproxy/>
    public class SpringConfig {
    }
    切面类
    与半注解形式一样
    测试类
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(classes = SpringConfig.class)
    public class Demo2 {@Autowiredprivate AccountService accountService;@Testpublic void run1(){accountService.save();}
    }
    出现异常时:前置方法,最终方法,异常方法都会执行
    http://www.dtcms.com/wzjs/230806.html

    相关文章:

  1. 国内永久在线免费建站百度客户端
  2. 医院网站建设的资料关键词排名优化易下拉软件
  3. 网站推广的策略方法要怎么做网络推广
  4. 做宣传册参考的网站营销计划怎么写
  5. 可以做热图的工具网站矿泉水软文广告500字
  6. 网站开发采集工具泉州seo网站排名
  7. 代运营靠谱吗优化网站搜索
  8. 广州机械加工网站seo站外优化
  9. 做网站建设的公司有哪些免费无代码开发平台
  10. 对网站内容建设的建议seo免费工具
  11. 深圳通信管理局网站网络优化是做啥的
  12. ps做素材下载网站有哪些河南网站推广公司
  13. 做网站app是什么h行业短视频优化
  14. 有没有专业做二手老车的网站怎么可以在百度发布信息
  15. 网站自适应框架优化排名推广技术网站
  16. 天河手机网站建设企业qq和个人qq有什么区别
  17. asp网站安全吗seo推广效果怎么样
  18. 做外贸网站能用虚拟主机吗长沙关键词优化方法
  19. 什么网站专门做外围的seo培训网的优点是
  20. 教学网站开发背景及意义网站制作方案
  21. 成品网站怎么被百度收录做seo排名
  22. 网站积分程序怎么建设制作一个网站大概需要多少钱
  23. 长沙正规制作网站公司属性词 关键词 核心词
  24. 网站开发文献综述发软文的平台
  25. 政府网站建设思路百度快照是怎么做上去的
  26. 邵东网站真实有效的优化排名
  27. 郑州工装定制公司南宁seo结算
  28. 怎样做网站图清晰app推广是做什么的
  29. 云服务器怎么做多个网站线上营销渠道主要有哪些
  30. wordpress怎么做伪静态徐州seo代理计费