SSM-1第一章 认识SSM框架和Redis
第一章 认识SSM框架和Redis
1.1 Spring框架
Sring理念
Ioc 控制反转 IOC是一个容器,在Spring中,它会认为一切Java资源都是JavaBean,容器的目标是管理Bean和它们之间的关系。
Aop 面向切面编程
第二章 Java设计模式
2.1 java 反射技术
Java反射技术 可以配置:类的全限定名、方法和参数,完成对象的初始化,甚至是反射某些方法。
在Java中反射是通过包java.lang.reflect.*实现的。
2.1.1通过反射构建对象
public class ReflectTmp{
public ReflectTmp(){};
public ReflectTmp(Srting str){};
public void sayHello(Srting str){};
}
/* 通过反射获取对象*/
public ReflectTmp getInstance()
{
try {
object =(ReflectTmp)Class.forName("com.xxx.ReflectTmp").getConstructor(String.class).newInstance("123");
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException | ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return object;
}
2.1.2 反射方法
public static Object reflectMethod()
{
Object returnobj = null;
ReflectTmpobj1 = newReflectTmp("456");
try {
Method method =ReflectTmp.class.getMethod("sayHello", String.class);
returnobj = method.invoke(obj1, "hello World !");
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return returnobj;
}
2.2 动态代理和责任链模式
动态代理的意义在于生成一个占位(又称为代理对象),来代理真实对象,从而控制真实对象的访问。
代理分为两个步骤:
- 代理对象与真实对象建立代理关系
- 实现代理对象的代理逻辑方法