没有合适的资源?快使用搜索试试~ 我知道了~
百知教育课堂笔记,真正的课堂笔记,主要讲的是使用方式
资源推荐
资源详情
资源评论
1.MVC 框架 struts2 springMVC Controller
持久化 框架 mybatis hibernate Model
项目管理 框架 spring 为javeEE开发提供更好的解决方案。
============================================================================================
2.spring :容器 工厂
:搭建工厂,生产并管理项目中的所有组件(action/service/dao/tx...)。
: 所有功能,都建立在工厂的支持下。
============================================================================================
3.spring工厂搭建过程:
3.1 导包
3.2 配置文件:告知spring那些组件需要生产
*位置:任意
*名称:任意 applicationContext.xml beans.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
<!-- 告知spring,需要生成如下组件
id:组件在工厂中的名字,唯一的。用户从工厂中获取对应的bean的对象。
-->
<bean id="us46" class="com.c46.service.UserServiceImpl"></bean>
<bean id="ud46" class="com.c46.dao.UserDAOImpl"></bean>
</beans>
3.3 启动工厂
ApplicationContext
ClassPathXmlApplicationContext
//启动工厂,并指定配置文件的位置,工厂会随之配置文件中的bean
ApplicationContext context=new ClassPathXmlApplicationContext("com/c46/config/applicationContext.xml");
//获取工厂中生产好的bean
持久化 框架 mybatis hibernate Model
项目管理 框架 spring 为javeEE开发提供更好的解决方案。
============================================================================================
2.spring :容器 工厂
:搭建工厂,生产并管理项目中的所有组件(action/service/dao/tx...)。
: 所有功能,都建立在工厂的支持下。
============================================================================================
3.spring工厂搭建过程:
3.1 导包
3.2 配置文件:告知spring那些组件需要生产
*位置:任意
*名称:任意 applicationContext.xml beans.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
<!-- 告知spring,需要生成如下组件
id:组件在工厂中的名字,唯一的。用户从工厂中获取对应的bean的对象。
-->
<bean id="us46" class="com.c46.service.UserServiceImpl"></bean>
<bean id="ud46" class="com.c46.dao.UserDAOImpl"></bean>
</beans>
3.3 启动工厂
ApplicationContext
ClassPathXmlApplicationContext
//启动工厂,并指定配置文件的位置,工厂会随之配置文件中的bean
ApplicationContext context=new ClassPathXmlApplicationContext("com/c46/config/applicationContext.xml");
//获取工厂中生产好的bean
UserDAO ud=(UserDAO)context.getBean("ud46");
UserService us=(UserService)context.getBean("us46");
==========================================================================================
4.IOC:Inverse Of Control 控制反转
:反转属性的赋值权,属性的赋值由代码中,反转到配置文件中,进而满足依赖关系。
:将具有依赖关系的双方的耦合度打散,使得整个项目中组件之间既可正常协作,有关系
松散,使得整个是便于维护的,是稳健的系统。
:在配置文件中为属性赋值:【依赖注入:dependency injection:DI】
==========================================================================================
5.DI方式:
5.1 set注入:借助set方法为属性赋值
<!-- jdk8中基本类型 + String -->
<property name="id" value="46"></property>
<property name="name" value="c46"></property>
<property name="gender" value="true"></property>
<!-- 对象类型 -->
<property name="ud" ref="ud47"></property>
<!-- 集合或数组 -->
<property name="list46">
<list>
<value>46</value>
<value>c46</value>
<value>true</value>
<ref bean="ud47"/>
</list>
</property>
<!-- map -->
<property name="map46">
<map>
<entry key="name" value="c46"></entry>
UserService us=(UserService)context.getBean("us46");
==========================================================================================
4.IOC:Inverse Of Control 控制反转
:反转属性的赋值权,属性的赋值由代码中,反转到配置文件中,进而满足依赖关系。
:将具有依赖关系的双方的耦合度打散,使得整个项目中组件之间既可正常协作,有关系
松散,使得整个是便于维护的,是稳健的系统。
:在配置文件中为属性赋值:【依赖注入:dependency injection:DI】
==========================================================================================
5.DI方式:
5.1 set注入:借助set方法为属性赋值
<!-- jdk8中基本类型 + String -->
<property name="id" value="46"></property>
<property name="name" value="c46"></property>
<property name="gender" value="true"></property>
<!-- 对象类型 -->
<property name="ud" ref="ud47"></property>
<!-- 集合或数组 -->
<property name="list46">
<list>
<value>46</value>
<value>c46</value>
<value>true</value>
<ref bean="ud47"/>
</list>
</property>
<!-- map -->
<property name="map46">
<map>
<entry key="name" value="c46"></entry>
剩余5页未读,继续阅读
资源评论
qq820037112
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功