## 屬性的依賴注入
spring在通過IOC創建這個對象的時候,如果這個對象還有屬性,就一并賦值.ID是在IOC的基礎上進行對象的屬性注入的.也就是說先有IOC,才能DI.
~~~
<bean id="user" class="com.like.serviceImpl.User ">
<property name="name" value="jack"/>
<property name="age" value="20"/>
</bean>
~~~
## ref屬性
~~~
<bean id="car" class="com.like.domain.Car">
<property name="name" value="蘭博基尼"/>
<property name="price" value="10000"/>
</bean>
<bean id="user" class="com.like.domain.User">
<property name="name" value="jack"/>
<property name="age" value="20"/>
<property name="car" ref="car"/> //ref針對的是對象類型
</bean>
~~~
~~~
public class User
{
private String name;
private Integer age;
private Car car; //有Car的對象
@Override
public String toString()
{
return "User{" +
"name='" + name + '\'' +
", age=" + age +
", car=" + car +
'}';
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public Integer getAge()
{
return age;
}
public void setAge(Integer age)
{
this.age = age;
}
public Car getCar()
{
return car;
}
public void setCar(Car car)
{
this.car = car;
}
}
~~~
結果:
```
User{name='jack', age=20, car=Car{name='蘭博基尼', price=10000.0}}
```
## 構造器依賴注入
條件是,必須有有參構造器.
配置:
~~~
<bean id="user" class="com.like.User">
<constructor-arg name="name" value="jack"/> //value針對的是基本類型和String類型
<constructor-arg name="age" value="20"/>
</bean>
~~~
bean:
~~~
public class User
{
private String name;
private Integer age;
public User()
{
}
public User(String name, Integer age)
{
this.name = name;
this.age = age;
}
@Override
public String toString()
{
return "User{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public Integer getAge()
{
return age;
}
public void setAge(Integer age)
{
this.age = age;
}
}
~~~
## P名稱空間屬性注入
條件:在配置文件中有P的名稱空間,底層還是用的set方式.
~~~
xmlns:p="http://www.springframework.org/schema/p" //:后面的 p 是別名
~~~
~~~
<bean id="car" class="com.like.domain.Car">
<property name="name" value="蘭博基尼"/>
<property name="price" value="10000"/>
</bean>
<bean id="user" class="com.like.domain.User" p:name="jack" p:age="20" p:car-ref="car"></bean>
~~~
## 復雜方式注入
~~~
public class CollBean
{
private String[] strings;
private List list;
private Map map;
private Properties properties;
@Override
public String toString()
{
return "CollBean{" +
"strings=" + Arrays.toString(strings) +
", list=" + list +
", map=" + map +
", properties=" + properties +
'}';
}
public String[] getStrings()
{
return strings;
}
public void setStrings(String[] strings)
{
this.strings = strings;
}
public List getList()
{
return list;
}
public void setList(List list)
{
this.list = list;
}
public Map getMap()
{
return map;
}
public void setMap(Map map)
{
this.map = map;
}
public Properties getProperties()
{
return properties;
}
public void setProperties(Properties properties)
{
this.properties = properties;
}
}
~~~
~~~
<bean id="car" class="com.like.domain.Car">
<property name="name" value="蘭博基尼"/>
<property name="price" value="200"/>
</bean>
<bean id="collBean" class="com.like.domain.CollBean">
<property name="strings">
<list>
<value>a</value>
<value>b</value>
<value>c</value>
</list>
</property>
<property name="list">
<list>
<value>1</value>
<value>2</value>
<ref bean="car"/>
</list>
</property>
<property name="map">
<map>
<entry key="key1" value="a"/>
<entry key="key2" value="b"/>
<entry key="key2" value-ref="car"/>
</map>
</property>
<property name="properties">
<props>
<prop key="hibernate.username">root</prop>
<prop key="hibernate.password">123</prop>
</props>
</property>
</bean>
~~~
結果:
```
CollBean{strings=[a, b, c], list=[1, 2, Car{name='蘭博基尼', price=200.0}], map={key1=a, key2=Car{name='蘭博基尼', price=200.0}}, properties={hibernate.password=123, hibernate.username=root}}
```
- Maven
- 概述
- 常用命令
- 生命周期
- scope詳解
- maven概念模型圖
- IDEA創建maven工程
- 創建maven web項目
- 沖突解決
- pom文件標簽詳解
- maven工程拆分與聚合的思想
- 父子工程的創建
- 工程和模塊的關系以及集成和依賴的概念
- 父子工程添加依賴
- 父子工程的三種啟動方式
- Struts2
- 執行流程
- 配置
- action的使用
- 獲取Servlet的API
- result標簽的視圖配置
- struts2屬性封裝
- struts2模型封裝
- OGNL
- 值棧(ValueStack)
- 值棧context區存數據
- 值棧root區
- struts2對el的增強
- #,%,$符號使用
- 值棧擴展
- 攔截器
- 自定義攔截器
- 方法攔截器
- 注解方式
- Hibernate
- 配置
- 簡單crud
- 持久化類編寫規范
- OID
- 持久化類三種狀態
- 一級緩存
- 查詢
- session與當前線程綁定
- hibernate一對多配置
- 冗余SQL語句的原因
- hibernate多對多配置
- 級聯操作
- 對象導航查詢
- JPA
- JPA單表CRUD
- JPA多種查詢
- JPA一對多關系映射
- JPA一對多操作
- JPA多對多關系映射
- JPA多對多操作
- QBC查詢
- 離線條件查詢(DetachedCriteria)
- SpringMVC
- 環境搭建
- 常用注解
- 請求參數綁定
- 綁定基本類型和字符串
- 綁定實體類型
- 解決中文亂碼
- 綁定集合類型
- 自定義類型轉換器
- 獲取Servlet的API
- 響應字符串
- 響應void
- 響應ModelAndView
- 響應forward和redirect
- 響應過濾靜態資源
- 響應json
- 文件上傳基礎
- SpringMVC上傳文件
- 跨服務器文件上傳
- 攔截器
- SpringMVC異常
- ControllerAdvice
- SpringMVC默認處理方式
- 概述
- @ExceptionHandler
- 消息轉換器
- SpringMVC跨域
- Spring
- 概述
- IoC快速入門
- ApplicationContext三個常用實現類
- beanFactory和ApplicationContext區別
- bean創建三種方式
- POJO和Javabean的區別
- bean作用范圍
- bean對象生命周期
- spring的依賴注入
- DI的屬性注入方式
- 常用注解
- Spring新注解
- Spring整合連接池
- Spring的IOC注解配置
- Spring完全使用注解
- Spring整合junit
- AOP
- AOP配置
- JDBCTemplate
- JDBCTemplate在IOC中使用
- JDBCTemplate的CRUD
- JDBCTemplate在dao中使用
- 聲明式事務
- spring事務API
- 事務XML配置
- 事務注解配置
- 全注解事務
- Spring編程式事務
- 整合SSH(XML版本)
- 整合SSH(半XML半注解)
- Spring5新特性
- MyBatis
- 概述
- 用maven創建MyBatis
- 將數據庫配置單獨文件
- typeAliases標簽
- MyBatis的CRUD
- MyBatis實現Dao層開發
- 使用dao和代理類的區別
- MyBatis連接池
- MyBatis事務
- MyBatis動態SQL
- 多表操作
- 多表一對一
- 多表一對多
- 多表多對多
- JNDI
- 延遲加載和立即加載
- 延遲加載
- 一級緩存
- 二級緩存
- MyBatis注解
- MyBatis注解CRUD
- 注解實體類屬性和字段對應關系
- MyBatis注解一對一和一對多
- MyBatis注解二級緩存
- SSM整合
- 搭建環境
- SpringBoot
- SpringBoot核心功能
- 快速入門
- SpringBoot配置文件
- yml配置文件語法
- 配置文件與配置類的屬性映射方式
- 端口和映射路徑
- 日志級別
- 訪問靜態資源
- SpringBoot注入方式一
- SpringBoot注入方式二
- 攔截器
- HikariCP連接池
- SpringBoot集成MyBatis
- 通用mapper
- SpringBoot事務
- SpringBoot集成Junit
- SpringBoot集成DataJPA
- SpringBoot集成Redis
- 使用SpringBoot提供的測試啟動類
- 使用MockMvc
- SpringCloud
- RestTemplate
- Eureka概述
- Eureka快速入門
- Eureka集群
- Eureka客戶端
- Eureka失效剔除和自我保護
- 負載均衡Ribbon
- Hystrix
- Hystrix服務降級
- Hystrix服務熔斷
- Feign
- Feign的熔斷機制
- Feign的請求壓縮和日志級別
- Zuul網關
- Zuul快速入門
- Zuul路由規則
- Zuul過濾器
- Zuul自定義過濾器
- Zuul負載均衡和熔斷
- Zuul高可用
- Zuul網關緩存
- SpringSecurity
- 快速入門
- SpringSecurity使用數據庫認證