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

免费网站空间申请哪个好做网站有骗子

免费网站空间申请哪个好,做网站有骗子,网站排名与什么有关系,wordpress宝塔开启ssl文章目录 spring分层架构表现层服务层#xff08;业务层#xff09;持久层 spring核心ioc#xff08;控制反转#xff09;1)**接下来是代码示例#xff1a;**2)**ioc容器的使用过程**3)ioc中的bean管理4)实例化bean的三种方式 aop#xff08;面向切面开发#xff09; 定… 文章目录 spring分层架构表现层服务层业务层持久层 spring核心ioc控制反转1)**接下来是代码示例**2)**ioc容器的使用过程**3)ioc中的bean管理4)实例化bean的三种方式 aop面向切面开发 定义优势AOP底层原理AOP相关的术语AOP入门aop注解开发aop纯注解开发Di依赖注入1属性的set方法注入值的方式2构造方法赋值的方法 多配置文件多配置文件 spring分层架构 表现层 springmvc 服务层业务层 spring ioc 持久层 mybatis mybatis plus hibernite 互联网项目多ssm结构 spring核心 ioc控制反转 ioc将对象的创建权利交给spring框架底层实际上是使用反射实现的。降低程序的耦合度 1)接下来是代码示例 创建一个空的maven项目 引入一些基本依赖 dependenciesdependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactIdversion5.0.2.RELEASE/version/dependencydependencygroupIdcommons-logging/groupIdartifactIdcommons-logging/artifactIdversion1.2/version/dependencydependencygroupIdlog4j/groupIdartifactIdlog4j/artifactIdversion1.2.12/version/dependencydependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion4.12/versionscopetest/scope/dependency/dependencies准备实体类 // 创建一个接口 public interface UserService {public void hello(); } // 创建一个实体类 public class UserServiceImpl implements UserService {Overridepublic void hello() {System.out.println(Hello, world!);} } 准备配置文件 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocation http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdbean idus class实体类的路径/bean /beans在test中测试 // 常规方法Testpublic void testUser() {// TODO: write test cases for UserServiceUserService userService new UserServiceImpl();userService.hello();} // 基于ioc容器管理的方法ioc是一个map key是对象的标识value是ioc创建的对象Testpublic void run1() {// 创建spring ioc工厂ApplicationContext ac new ClassPathXmlApplicationContext(applicationContext.xml);// 获取beanUserService userService (UserService) ac.getBean(us);userService.hello();}上面就是一个关于ioc容器的示例 2)ioc容器的使用过程 ApplicationContext接口这个工厂接口使用这个接口就可以获得相应的Bean对象该对象下有两个实现类 ClassPathXmlApplicationContext加载类路径下的spring配置文件常用FileSystemXmlApplicationContext加载本地磁盘下的spring配置文件让项目和配置文件分离管理不常用 3)ioc中的bean管理 id属性bean的别名取名要求必须要字母开头可以使用数字连字符下划线字母不能出现特殊字符class属性bean对象的全路径scope属性 bean对象的作用范围 singleton单例默认生命周期和配置文件一样prototype多例不是加载配置文件时创建而是在获取实例对象时创建request 多例不常用应用于web项目中每个请求都会创建一个新的实例对象session多例不常用应用于web项目中向一个http session中共享一个实例 init-methodbean对象创建时可以配置一个指定的方法自动调用destory-methodbean对象销毁时可以配置一个指定的方并自动调用 4)实例化bean的三种方式 默认是无参的构造方法 bean idus class实体类的路径/bean静态工厂实例化方法好处是可以自己编写业务逻辑 准备一个静态工厂类 public class StaticFactory {public static UserService createUser() {// 编写业务逻辑// ......return new UserServiceImpl();} }在xml配置文件中使用 bean idus1 classcom.qc.util.StaticFactory factory-methodcreateUser/bean实例化工厂实例化方式 准备一个可以实例化的类 public class DFactory {public UserService createUser() {// 编写业务逻辑return new UserServiceImpl();} }在xml配置文件中使用 bean idfactory classcom.qc.util.DFactory/beanbean idus2 factory-beanfactory factory-methodcreateUser/beanaop面向切面开发 定义 ​ 是一种编辑的范式是OOP的延续也是Spring框架中函数编程的一种衍生范式利用AOP可以对业务的各个部分进行隔离从而似的业务逻辑各部分之间的耦合度降低提高了程序的重用性同时提高了开发的效率AOP采用横向抽取机制取代了传统纵向继承体系。 优势 运行期间不修改源代码的情况下对已有的方法进行增强减少重复代码提高开发效率方便维护 AOP底层原理 如果使用接口则使用JDK动态代理技术如果没有使用接口使用的是继承则是cglib代理 AOP相关的术语 Joinpoint连接点所谓连接点是指那些被连接到的点在spring中这些带点指的是方法因为spring只支持方法类型的节点Pointcut切入点所谓切入点是我们要对哪些Joinpoint进行拦截的定义Advice通知\通知所谓通知就是指拦截到Joinpoint之后所要做的情况就就是通知通知分为前置通知后置通知异常通知最终通知环绕通知切面类中要完成的功能Target目标对象代理的目标对象Weaving织入是指把增强应用到目标对象来创建新的代理对象的过程Proxy代理一个类被AOP织入增强后就产生一个结果代理类Aspect切面是切入点通知的结合是自己编写和配置 AOP入门 导入坐标依赖 dependencygroupIdaopalliance/groupIdartifactIdaopalliance/artifactIdversion1.0/version/dependency!--Spring Aspects--dependencygroupIdorg.springframework/groupIdartifactIdspring-aspects/artifactIdversion5.0.2.RELEASE/version/dependency!--aspectj--dependencygroupIdorg.aspectj/groupIdartifactIdaspectjweaver/artifactIdversion1.8.3/version/dependency?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:aophttp://www.springframework.org/schema/aopxsi:schemaLocation http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd /beans编写spirng配置文件中AOP的配置部分 !-- bean管理--bean idus classcom.qc.service.impl.UserServiceImpl/bean idmyAspect classcom.qc.util.MyAspect/!-- 配置aop--aop:config!-- 配置切面--aop:aspect refmyAspect!-- 前缀通知--aop:before methodlog1 pointcutexecution(public void com.qc.service.impl.UserServiceImpl.save())/!-- 后置通知--aop:after-returning methodlog2pointcutexecution(public void com.qc.service.impl.UserServiceImpl.save())/!-- 异常通知--aop:after-throwing methodlog3pointcutexecution(public void com.qc.service.impl.UserServiceImpl.save())/!-- 最终通知--aop:after methodlog4pointcutexecution(public void com.qc.service.impl.UserServiceImpl.save())/!-- 环绕通知--aop:around methodaroundLogpointcutexecution(public void com.qc.service.impl.UserServiceImpl.save())//aop:aspect/aop:configimport org.aspectj.lang.ProceedingJoinPoint;public class MyAspect {// 自定义切面类 切入点通知//通知public void log1() {System.out.println(前置增强的);}public void log2() {System.out.println(后置增强的);}public void log3() {System.out.println(异常增强的);}public void log4() {System.out.println(最终增强的);}public void aroundLog(ProceedingJoinPoint point) {try {log1();point.proceed(); // 目标方法调用log2();} catch (Throwable e) {e.printStackTrace();log3();} finally {log4();}} }注意环绕通知使用的接口 通知类型 前置通知目标方法执行前进行增强后置通知目标方法执行后进行增强异常通知目标方法出现异常后进行增强最终通知目标方法无论是否异常都进行增强环绕通知目标方法执行前后都进行增强不过需要自己书写 切入点表达式 execution[修饰符] 返回值 包名.类名.方法名参数修饰符可以省略不写返回值类型不能省略根据方法来编写返回值可以用星号来代替包名类型方法名是不能省略的但是可以用星号来代替也可以部分代替参数如果是一个可以用星号来代替如果是多个可以使用两个点 因此比较通用的表达式 execution( com.qc.*.Service.save(…)) aop注解开发 给切面添加Aspect编写增强的方法使用通知类型注解声明 !-- 开启注解扫描--context:component-scan base-packagecom.qc/!-- 开启自动代理--aop:aspectj-autoproxy/Aspect Component public class MyAspect {// 自定义切面类 切入点通知//通知Before(execution(* com.qc.*.*.*ServiceImpl.save(..)))public void log1() {System.out.println(前置增强的);}AfterReturning(execution(* com.qc.*.*.*ServiceImpl.save*(..)))public void log2() {System.out.println(后置增强的);}AfterThrowing(execution(* com.qc.*.*.*ServiceImpl.save*(..)))public void log3() {System.out.println(异常增强的);}After(execution(* com.qc.*.*.*ServiceImpl.save*(..)))public void log4() {System.out.println(最终增强的);}Around(execution(* com.qc.*.*.*ServiceImpl.save*(..)))public void aroundLog(ProceedingJoinPoint point) {try {log1();point.proceed(); // 目标方法调用log2();} catch (Throwable e) {e.printStackTrace();log3();} finally {log4();}} }在每个方法上使用注解进行配置和配置文件类似 通知类型注解 Before 前置注解AfterReturning 后置注解AfterThrowing 异常注解After 最终注解Round 环绕注解 注意在配置文件中开启自动代理 aop纯注解开发 EnableAspectJAutoProxy 开启自动代理 Di依赖注入 依赖注入在spring框架负责创建bean对象时动态的将对象注入到其他的bean对象中 1属性的set方法注入值的方式 声明变量并在需要依赖注入的地方设置set方法 在xml文件中配置该变量的值 bean idus classcom.qc.service.impl.UserServiceImplproperty nameuserDao ref/propertyproperty namename value/property/bean参数说明如果property中的是一个简单类型基本类型和字符串那么就使用value否则就使用ref 2构造方法赋值的方法 在需要的地方添加构造方法 在配置文件中使用带参数的构造方法传参 bean iduserDao classcom.qc.dao.impl.UserDaoImpl/beanbean idus classcom.qc.service.impl.UserServiceImplconstructor-arg nameuserDao refuserDao/constructor-arg/bean其他类型的参数传参 准备一个java类 public class CollectionBean {private String[] strs;private ListString list;private MapString, String map;private Properties properties;public Properties getProperties() {return properties;}public void setProperties(Properties properties) {this.properties properties;}public MapString, String getMap() {return map;}public void setMap(MapString, String map) {this.map map;}public String[] getStrs() {return strs;}public ListString getList() {return list;}public void setList(ListString list) {this.list list;}public CollectionBean() {}public void setStrs(String[] strs) {this.strs strs;}public CollectionBean(String[] strs) {this.strs strs;} }不可变数组 bean idco classcom.qc.service.CollectionBeanproperty namestrsarrayvalue小美/valuevalue小张/valuevalue小王/value/array/property/bean可变集合 bean idco classcom.qc.service.CollectionBeanproperty namelistlistvalue张三/valuevalue李四/valuevalue王五/value/list/property/beanmap集合 bean idco classcom.qc.service.CollectionBeanproperty namemapmapentry keyname valuezhangsan/entryentry keyage value18/entry/map/property/bean其他类型 bean idco classcom.qc.service.CollectionBeanproperty namepropertiespropsprop keyusernamezhangsan/propprop keypassword1234/prop/props/property/bean多配置文件 在配置文件中使用 import resourceapplicationContext.xml/import创建工厂时直接加载多个配置文件 ApplicationContext ac new ClassPathXmlApplicationContext(applicationContext.xml,applicationContext1.xml);​ propsprop keyusernamezhangsan/propprop keypassword1234/prop/props/property/bean多配置文件 在配置文件中使用 import resourceapplicationContext.xml/import创建工厂时直接加载多个配置文件 ApplicationContext ac new ClassPathXmlApplicationContext(applicationContext.xml,applicationContext1.xml);​
http://www.w-s-a.com/news/112338/

相关文章:

  • 网站建设费用怎么做分录做校园网站代码
  • 网站改版做重定向福州网站建设思企
  • 网站建设全流程企业形象网站开发业务范畴
  • wordpress无法查看站点西安优秀高端网站建设服务商
  • 固始网站制作熟悉免费的网络营销方式
  • 做网站到a5卖站赚钱搜索引擎优化代理
  • 沈阳网站建设包括win10优化
  • 做百度手机网站点击软网站seo优化徐州百度网络
  • 徐州专业网站制作标志设计作业
  • 自己可以做网站空间吗海天建设集团有限公司网站
  • 教学督导网站建设报告aspcms网站图片不显示
  • 网站开发公司成本是什么门户网站宣传方案
  • 上海 企业网站建设网站怎么开通微信支付
  • 饮料网站建设wordpress主题猫
  • 网站建设需要编码不有没有专门的网站做品牌授权的
  • 做爰在线网站免费空间列表
  • 网站外链建设工作总结郑州网站建设扌汉狮网络
  • 建设企业网站的需要多长时间网站使用说明书模板
  • 建网站首页图片哪里找263企业邮箱网页版登录
  • 盐城网站建设电话高端定制网站
  • 成都网站seo技术施工企业样板先行制度
  • 高端网站建设电话河北建筑工程信息网站
  • 亲 怎么给一个网站做备份财务系统有哪些软件
  • wordpress重新手机优化专家下载
  • 怎样把网站做成软件设计工作室怎么接单
  • html网站设计实例代码重庆多个区划定风险区
  • 推广方案设计同一个网站可以同时做竞价和优化
  • 论坛网站开发 go电商扶贫网站建设
  • 个人建站教程优秀的定制网站建设
  • 农村建设集团有限公司网站下载百度极速版