最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于Spring p標(biāo)簽和c標(biāo)簽注入方式

 更新時間:2021年09月26日 09:51:01   作者:迷惑的菜鳥  
這篇文章主要介紹了Spring p標(biāo)簽和c標(biāo)簽注入方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

Spring p和c標(biāo)簽注入方式

1.編寫實體類

package com.ming04.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User {
    private int id;
    private String name;
}

2.配置文件(重點)

<?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:p="http://www.springframework.org/schema/p"
       xmlns:c="http://www.springframework.org/schema/c"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">
    <!-- p命名空間注入 ,可以直接注入屬性的值 :property -->
    <bean id="user" class="com.ming04.pojo.User" p:name="秦小東" p:id="18"/>
    <!-- c命名空間注入 可以構(gòu)造器注入屬性的值 :construct-args -->
    <bean id="user2" class="com.qin.pojo.User" c:id="19" c:name="狂神" />
</beans>

3.測試

  @Test
    public void Text(){
       ApplicationContext context = new ClassPathXmlApplicationContext("Beans04.xml");
        User user = (User) context.getBean("user2");
        System.out.println(user);
    }

spring Bean注入和P標(biāo)簽使用

1.構(gòu)造方法參數(shù)

對應(yīng) 配置文件 <constructor-arg> 元素

可以index|name|type 三選一 、三選二 ; ref|value 二選一

2.setter方法注入(開發(fā)推薦)

為需要注入屬性提供setter方法

配置 每個注入屬性, 對應(yīng)<property> 元素

3.p名稱空間的使用

spring2.5以后,為了簡化setter方法屬性注入,引用p名稱空間的概念,可以將<property> 子元素,簡化為<bean>元素屬性配置 ??!

a.

在applicationContext.xml 引入p 名稱空間

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
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.xsd">

b. 簡化注入的配置

4.集合類型的屬性注入(了解)

Spring 對每個常用集合對象,提供單獨元素完成注入

  • List 對象 ---- <list> 元素
  • Set 對象 ---- <set> 元素
  • Map對象 ----<map>元素
  • Properties 對象 ---- <props> 元素

集合屬性的注入,主要用于框架的配置 !

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

盈江县| 右玉县| 曲靖市| 夏津县| 万山特区| 木兰县| 三门峡市| 祁东县| 钦州市| 台前县| 临泉县| 安陆市| 平遥县| 宜阳县| 宁化县| 乌什县| 邹平县| 大足县| 科尔| 苍梧县| 河东区| 四会市| 天镇县| 鱼台县| 张家口市| 江口县| 永年县| 恩平市| 甘泉县| 屯留县| 积石山| 新乡县| 九江县| 平顶山市| 达州市| 昌都县| 隆化县| 台北县| 宁南县| 小金县| 高要市|