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

同城版网站建设网上营销培训课程

同城版网站建设,网上营销培训课程,公司网络规划设计方案,那个网站平台可以做兼职系列文章目录 Spring中AOP技术的学习 文章目录系列文章目录前言一、AOP核心概念二、AOP入门案例1.AOP入门案例思路分析2.AOP入门案例实现三、AOP工作流程四、AOP切入点表达式五、AOP通知类型六、案例:测量业务层接口万次执行效率1.项目结构2.实现类七、AOP获取通知…

系列文章目录

Spring中AOP技术的学习


文章目录

  • 系列文章目录
  • 前言
  • 一、AOP核心概念
  • 二、AOP入门案例
    • 1.AOP入门案例思路分析
    • 2.AOP入门案例实现
  • 三、AOP工作流程
  • 四、AOP切入点表达式
  • 五、AOP通知类型
  • 六、案例:测量业务层接口万次执行效率
    • 1.项目结构
    • 2.实现类
  • 七、AOP获取通知数据
  • 八、案例:百度网盘密码数据兼容处理
  • 总结


前言


一、AOP核心概念

在这里插入图片描述

在这里插入图片描述

二、AOP入门案例

1.AOP入门案例思路分析

在这里插入图片描述

2.AOP入门案例实现

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

项目结构
在这里插入图片描述

三、AOP工作流程

在这里插入图片描述
在这里插入图片描述

四、AOP切入点表达式

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

五、AOP通知类型

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

六、案例:测量业务层接口万次执行效率

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

1.项目结构

在这里插入图片描述

2.实现类

MyAdvice

package org.example.aop;import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;@Component
@Aspect
public class MyAdvice {//匹配业务层的所有方法@Pointcut("execution(* org.example.service.*Service.*(..))")private void servicePt() {}@Around("servicePt()")public Object runSpeed(ProceedingJoinPoint point) throws Throwable {//一次执行的签名信息Signature signature = point.getSignature();//获取执行的方法名和类型名String className = signature.getDeclaringTypeName();String methodName = signature.getName();Object ret = null;//记录程序当前执行(开始时间)long begin = System.currentTimeMillis();//业务执行次数for (int i = 0; i < 10000; i++) {//表示对原始操作的调用ret = point.proceed();}//记录程序当前执行时间(结束时间)long end = System.currentTimeMillis();//计算时间差long totalTime = end - begin;//输出信息System.out.println("执行"+className+"."+methodName+"万次消耗时间:" + totalTime + "ms");return ret;}
}

JdbcConfig

package org.example.config;import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;import javax.sql.DataSource;public class JdbcConfig {@Value("${jdbc.driver}")private String drive;@Value("${jdbc.url}")private String url;@Value("${jdbc.username}")private String username;@Value("${jdbc.password}")private String password;@Beanpublic DataSource dataSource(){DruidDataSource ds=new DruidDataSource();ds.setDriverClassName(drive);ds.setUrl(url);ds.setUsername(username);ds.setPassword(password);return ds;}
}

MybatisConfig

package org.example.config;import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;import javax.sql.DataSource;public class MybatisConfig {//定义bean,SqlSessionFactoryBean,用于产生SqlSessionFactory对象@Beanpublic SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource){SqlSessionFactoryBean ssfb=new SqlSessionFactoryBean();ssfb.setTypeAliasesPackage("org.example.domain");ssfb.setDataSource(dataSource);return ssfb;}//定义bean,返回MapperScannerConfigurer对象@Beanpublic MapperScannerConfigurer mapperScannerConfigurer(){MapperScannerConfigurer msc=new MapperScannerConfigurer();msc.setBasePackage("org.example.dao");return msc;}
}

SpringConfig

package org.example.config;import org.springframework.context.annotation.*;@Configuration
@ComponentScan("org.example")
@PropertySource("classpath:jdbc.properties")
@Import({JdbcConfig.class,MybatisConfig.class})
@EnableAspectJAutoProxy
public class SpringConfig {
}

AccountDao

package org.example.dao;import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.domain.Account;import java.util.List;public interface AccountDao {@Insert("insert into tbl_account(name,money)values(#{name},#{money})")void save(Account account);@Delete("delete from tbl_account where id = #{id} ")void delete(Integer id);@Update("update tbl_account set name = #{name} , money = #{money} where id = #{id} ")void update(Account account);@Select("select * from tbl_account")List<Account> findAll();@Select("select * from tbl_account where id = #{id} ")Account findById(Integer id);
}

Account

package org.example.domain;public class Account {private Integer id;private String name;private Double money;public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Double getMoney() {return money;}public void setMoney(Double money) {this.money = money;}@Overridepublic String toString() {return "Account{" +"id=" + id +", name='" + name + '\'' +", money=" + money +'}';}
}

AccountService

package org.example.service;import org.example.domain.Account;import java.util.List;public interface AccountService {void save(Account account);void delete(Integer id);void update(Account account);List<Account> findAll();Account findById(Integer id);
}

AccountServiceImpl

package org.example.service.impl;import org.example.dao.AccountDao;
import org.example.domain.Account;
import org.example.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.List;@Service
public class AccountServiceImpl implements AccountService {@Autowiredprivate AccountDao accountDao;public void save(Account account) {accountDao.save(account);}public void delete(Integer id) {accountDao.delete(id);}public void update(Account account) {accountDao.update(account);}public List<Account> findAll() {return accountDao.findAll();}public Account findById(Integer id) {return accountDao.findById(id);}
}

测试类

package org.example.service;import org.example.config.SpringConfig;
import org.example.domain.Account;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import java.util.List;//Spring集成Junit必须要写的注解,否则找不到类
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConfig.class)
public class AccountServiceTest {@Autowiredprivate AccountService accountService;@Testpublic void testFindById(){Account account=accountService.findById(2);System.out.println(account);}@Testpublic void testFindAll(){List<Account> accounts=accountService.findAll();System.out.println(accounts);}
}

七、AOP获取通知数据

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

八、案例:百度网盘密码数据兼容处理

在这里插入图片描述
在这里插入图片描述
项目结构

在这里插入图片描述

DataAdvice

package org.example.aop;import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;@Component
@Aspect
public class DataAdvice {@Pointcut("execution(boolean org.example.service.*Service.openURL(*,*))")private void servicePt(){}@Around("servicePt()")public Object trimStr(ProceedingJoinPoint point) throws Throwable {Object[] args = point.getArgs();for (int i = 0; i < args.length; i++) {//判断参数是否为字符串if (args[i].getClass().equals(String.class)){args[i]=args[i].toString().trim();}}Object ret = point.proceed(args);return ret;}
}

SpringConfig

package org.example.config;import org.aspectj.lang.annotation.Around;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;@Configuration
@ComponentScan("org.example")
@EnableAspectJAutoProxy
public class SpringConfig {
}

ResourceDaoImpl

package org.example.dao.impl;import org.example.dao.ResourceDao;
import org.springframework.stereotype.Repository;@Repository
public class ResourceDaoImpl implements ResourceDao {public boolean readResource(String url, String password) {//模拟校验return password.equals("root");}
}

ResourceDao

package org.example.dao;public interface ResourceDao {public boolean readResource(String url,String password);
}

ResourceServiceImpl

package org.example.service.impl;import org.example.dao.ResourceDao;
import org.example.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;@Service
public class ResourceServiceImpl implements ResourceService {@Autowiredprivate ResourceDao resourceDao;public boolean openURL(String url, String password) {return resourceDao.readResource(url,password);}
}

ResourceService

package org.example.service;public interface ResourceService {public boolean openURL(String url,String password);
}

App

import org.example.config.SpringConfig;
import org.example.service.ResourceService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;public class App {public static void main(String[] args) {ApplicationContext ctx=new AnnotationConfigApplicationContext(SpringConfig.class);ResourceService resourceService = ctx.getBean(ResourceService.class);boolean flag = resourceService.openURL("http://www.baidu.com", "root");System.out.println(flag);}
}

记得加入相应依赖


总结

AOP主要用作方法的增强,底层使用代理,本节主要讲解了AOP方法的作用和相关案例,详细讲解了AOP相关的核心概念,如:切入点表达式,通知类型等。
参考视频


文章转载自:
http://outgush.sqLh.cn
http://crockery.sqLh.cn
http://blackpoll.sqLh.cn
http://aesthete.sqLh.cn
http://cytotechnician.sqLh.cn
http://ergal.sqLh.cn
http://trotter.sqLh.cn
http://popinjay.sqLh.cn
http://athabascan.sqLh.cn
http://aluminum.sqLh.cn
http://embryoid.sqLh.cn
http://birotation.sqLh.cn
http://paranoea.sqLh.cn
http://himalaya.sqLh.cn
http://resuscitator.sqLh.cn
http://inclement.sqLh.cn
http://snakeskin.sqLh.cn
http://roughout.sqLh.cn
http://jauntily.sqLh.cn
http://snacketeria.sqLh.cn
http://klunk.sqLh.cn
http://woolwork.sqLh.cn
http://flightiness.sqLh.cn
http://preconception.sqLh.cn
http://recife.sqLh.cn
http://regent.sqLh.cn
http://compunction.sqLh.cn
http://thickhead.sqLh.cn
http://belee.sqLh.cn
http://meroplankton.sqLh.cn
http://axiologist.sqLh.cn
http://freshman.sqLh.cn
http://inositol.sqLh.cn
http://vicarage.sqLh.cn
http://arret.sqLh.cn
http://bale.sqLh.cn
http://astrand.sqLh.cn
http://dharma.sqLh.cn
http://oscilloscope.sqLh.cn
http://fourpence.sqLh.cn
http://jg.sqLh.cn
http://wrath.sqLh.cn
http://karun.sqLh.cn
http://mesenteron.sqLh.cn
http://continency.sqLh.cn
http://pelage.sqLh.cn
http://schizogenous.sqLh.cn
http://ladle.sqLh.cn
http://unspeak.sqLh.cn
http://goldfish.sqLh.cn
http://pressor.sqLh.cn
http://dimidiate.sqLh.cn
http://dele.sqLh.cn
http://utilizable.sqLh.cn
http://agonising.sqLh.cn
http://harmost.sqLh.cn
http://conformation.sqLh.cn
http://intransitively.sqLh.cn
http://expletory.sqLh.cn
http://litterateur.sqLh.cn
http://aesthophysiology.sqLh.cn
http://pederasty.sqLh.cn
http://erratic.sqLh.cn
http://uther.sqLh.cn
http://voltaic.sqLh.cn
http://antispeculation.sqLh.cn
http://tonk.sqLh.cn
http://enswathe.sqLh.cn
http://surpass.sqLh.cn
http://daintiness.sqLh.cn
http://joviologist.sqLh.cn
http://masut.sqLh.cn
http://gaggery.sqLh.cn
http://roomie.sqLh.cn
http://hyperaphia.sqLh.cn
http://telestich.sqLh.cn
http://jarosite.sqLh.cn
http://revoke.sqLh.cn
http://criticism.sqLh.cn
http://kilogramme.sqLh.cn
http://ardently.sqLh.cn
http://retrenchment.sqLh.cn
http://succus.sqLh.cn
http://tropaeolum.sqLh.cn
http://effluvia.sqLh.cn
http://blazon.sqLh.cn
http://porno.sqLh.cn
http://menhaden.sqLh.cn
http://superheavy.sqLh.cn
http://veal.sqLh.cn
http://glycogenolysis.sqLh.cn
http://rewrite.sqLh.cn
http://cloudwards.sqLh.cn
http://classroom.sqLh.cn
http://sonant.sqLh.cn
http://honolulan.sqLh.cn
http://quin.sqLh.cn
http://hydroxyketone.sqLh.cn
http://beaut.sqLh.cn
http://iliac.sqLh.cn
http://www.15wanjia.com/news/102677.html

相关文章:

  • 企业网站设计步骤免费p站推广网站入口
  • 贸易公司寮步网站建设哪家好百度关键词屏蔽
  • 高性能网站建设进阶指南 pdf简单网页制作模板
  • wordpress显示评论者地理位置 浏览器seo工作室
  • 上海最专业的网站建设公司东莞网站快速排名提升
  • 推荐做问卷的网站长春疫情最新消息
  • 深圳网站开发电话谷歌seo最好的公司
  • 政务网站建设优化设计答案大全
  • 陆良网站建设定制网站建设
  • 备案号被取消 没有重新备案网站会被关闭吗天津网站策划
  • 网站自然排名这么做关键词优化意见
  • 公司怎么找做网站seo描述是什么
  • 高乐雅官方网站 哪个公司做的优化是什么意思?
  • 为什么简洁网站会受到用户欢迎怎样做市场营销策划
  • 一级建造师求职网seo关键词排名如何
  • 深圳专业定制建站公司app推广拉新工作可靠吗
  • 口碑好网站建设公司找精准客户的app
  • 可以做mv的视频网站济南seo快速霸屏
  • 免费个人网站服务器推荐怎么让网站排名上去
  • 建设银行官方网站客户资料修改品牌运营策略有哪些
  • 做期货应关注什么网站营销推广是什么
  • 网站怎样制作 优帮云电商代运营十大公司排名
  • 购物网站建设所需软件百度客服24小时电话人工服务
  • php 手机网站开发指定关键词排名优化
  • 雅思培训班价格一般多少sem seo
  • wap建站系统开源今日新闻摘抄十条简短
  • 人工智能公众号seo新站如何快速排名
  • 做游戏网站的前景推广公司
  • 用自己的电脑做服务器搭建网站中级经济师考试
  • 无锡网站建设详细内容的网站建设