1.ioc
1 pom导包spring-mvc
2 创建资源文件xml、pojo对象()
3 资源文件中配置bean,对pojo对象属性
4 测试中直接getBean获取。
1.1 一些不重要的
取别名:在资源文件中取别名,一种是直接在bean标签中用name,另一种是单独设置标签alias
合并配置:在资源配置文件中标签import可以导入合并
1.2 依赖(属性)注入
1.2.1 构造器注入
<constructor-arg index/type/name= vlaue="">
1.2.2 set注入
这是在默认无参的情况下。各种类型情况下。
value是直接命名值,ref表示引用值。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">
<bean id="address" class="com.kuang.pojo.Address">
<property name="address" value="河南"/>
</bean>
<bean id="student" class="com.kuang.pojo.Student">
<!-- 第一种注入:普通值注入,value-->
<property name="name" value="houshuaixin"/>
<!-- 第二种注入:bean注入,ref-->
<property name="address" ref="address"/>
<!-- 第三种注入:数组的注入-->
<property name="books">
<array>
<value>红楼梦</value>
<value>西游记</value>
<value>水浒传</value>
<value>三国演义</value>
</array>
</property>
<!-- list注入-->
<property name="hobbys">
<list>
<value>听歌</value>
<value>敲代码</value>
<value>看电影</value>
</list>
</property>
<!-- Map注入-->
<property name="card">
<map>
<entry key="身份证" value="1111111"/>
<entry key="银行卡" value="2222222"/>
</map>
</property>
<!-- Set注入-->
<property name="games">
<set>
<value>CF</value>
<value>LOL</value>
<value>BOB</value>
</set>
</property>
<!-- null注入-->
<property name="wife">
<null></null>
</property>
<!-- Properties注入-->
<property name="info">
<props>
<prop key="学号">215151</prop>
<prop key="性别">男</prop>
</props>
</property>
</bean>
</beans>
1.2.3 拓展方式注入(p、c命名空间)
头文件取xmlns到schema/p或者c
xmlns:p="http://www.springframework.org/schema/p"
xmlns:c="http://www.springframework.org/schema/c"
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:c="http://www.springframework.org/schema/c"
xsi:schemaLocation="http://ww