本周Spring学习过的内容:
三元运算符和if语句的区别:
if语句
if(条件判断语句){
条件为true时}else {
条件为false时}
三元运算符
条件判断语句?A(条件为true):B(条件为false);
Spring IOC&Di
IOC(控制反转) DI(依赖注入)
在Spring的环境下这两个概念是等同的,控制反转是通过依赖注入来实现的。
Spring IOC容器负责创建Bean,并通过容器将Bean注入到需要的Bean对象上,同时Spring IOC容器还负责维护Bean对象之间的关系。 Spring提供了XML配置和JAVA配置等方式:
Service
public class AyUserServiceImpl implements AyUserService{
@Resource
private AySserDao ayUserDao;
public Listfindall(){
return ayUserDao.findall();
}
}
SpringAOP:
代理模式:
SpringAOP使用的是动态代理模式:
代理模式定义如下:
(1)代理模式给某一个对象提供一个代理或占位符,并代理对象来空时对原对象的访问。
(2)代理模式是一种对象结构型模式。在代理模式中引入了一个新的代理对象,代理对象在客户端对象和目标对象在之间起到中介作用,它去掉客户不能看到的内容和服务或者增添客户需要的额外的新服务。
(3)代理模式的结构比较简单,其核心是代理类,为了让客户能够一致性的对待真实对象,在代理模式中引入抽象层。
代理模式包含以下三个角色:
Subject(抽象主题角色)
Proxy(代理主题角色)
RealSubject(真实主题角色)
在编译阶段就要为每个RealSubject类创建一个Proxy类,当需要代理的类很多事,就会出现大量的Proxy类,所以可以使用JDK动态代理解决这个问题。