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

Spring依賴(lài)注入多種類(lèi)型數(shù)據(jù)的示例代碼

 更新時(shí)間:2022年03月31日 16:15:55   作者:樂(lè)道樂(lè)  
這篇文章主要介紹了Spring依賴(lài)注入多種類(lèi)型數(shù)據(jù),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

Student實(shí)體類(lèi)

package entity;
import java.util.*;
/**
 * @author LeDao
 * @company
 * @create 2022-02-13 21:26
 */
public class Student {
    private int id;
    private String name;
    private StudentClass studentClass;
    private String[] books;
    private List<String> hobbies;
    private Map<String, String> cards;
    private Set<String> games;
    private String wife;
    private Properties info;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    public String getName() {
        return name;
    public void setName(String name) {
        this.name = name;
    public StudentClass getStudentClass() {
        return studentClass;
    public void setStudentClass(StudentClass studentClass) {
        this.studentClass = studentClass;
    public String[] getBooks() {
        return books;
    public void setBooks(String[] books) {
        this.books = books;
    public List<String> getHobbies() {
        return hobbies;
    public void setHobbies(List<String> hobbies) {
        this.hobbies = hobbies;
    public Map<String, String> getCards() {
        return cards;
    public void setCards(Map<String, String> cards) {
        this.cards = cards;
    public Set<String> getGames() {
        return games;
    public void setGames(Set<String> games) {
        this.games = games;
    public String getWife() {
        return wife;
    public void setWife(String wife) {
        this.wife = wife;
    public Properties getInfo() {
        return info;
    public void setInfo(Properties info) {
        this.info = info;
    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", studentClass=" + studentClass +
                ", books=" + Arrays.toString(books) +
                ", hobbies=" + hobbies +
                ", cards=" + cards +
                ", games=" + games +
                ", wife='" + wife + '\'' +
                ", info=" + info +
                '}';
}

StudentsClass實(shí)體類(lèi)

package entity;
/**
 * @author LeDao
 * @company
 * @create 2022-02-14 14:11
 */
public class StudentClass {
    private int id;
    private String name;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    @Override
    public String toString() {
        return "Class{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }
}

beans.xml

下面展示的數(shù)據(jù)類(lèi)型有:一般類(lèi)型、對(duì)象、數(shù)組、List、Map、Set、空值、Properties

<?xml version="1.0" encoding="UTF-8"?>
<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.xsd">
    <bean id="studentClass1" class="entity.StudentClass">
        <property name="id" value="1"/>
        <property name="name" value="軟件工程3班"/>
    </bean>
    <bean id="user1" class="entity.Student">
        <!--一般類(lèi)型-->
        <property name="id" value="1"/>
        <property name="name" value="tom"/>
        <!--對(duì)象-->
        <property name="studentClass" ref="studentClass1"/>
        <!--數(shù)組-->
        <property name="books">
            <array>
                <value>Java編程思想</value>
                <value>MySQL必知必會(huì)</value>
                <value>平凡的世界</value>
            </array>
        </property>
        <!--List-->
        <property name="hobbies">
            <list>
                <value>唱</value>
                <value>跳</value>
                <value>rap</value>
                <value>打籃球</value>
            </list>
        </property>
        <!--Map-->
        <property name="cards">
            <map>
                <entry key="身份證" value="123"/>
                <entry key="校園卡" value="321"/>
            </map>
        </property>
        <!--Set-->
        <property name="games">
            <set>
                <value>LOL</value>
                <value>DNF</value>
                <value>COC</value>
            </set>
        </property>
        <!--空值-->
        <property name="wife">
            <null/>
        </property>
        <!--Properties-->
        <property name="info">
            <props>
                <prop key="userName">root</prop>
                <prop key="password">123456</prop>
            </props>
        </property>
    </bean>
</beans>

測(cè)試

import config.MyConfig;
import entity.Student;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
 * @author LeDao
 * @company
 * @create 2022-02-12 15:56
 */
public class MyTest {
    public static void main(String[] args) {
        ApplicationContext context=new ClassPathXmlApplicationContext("beans.xml");
        Student student = (Student) context.getBean("user1");
        System.out.println(student);
    }
}

到此這篇關(guān)于Spring依賴(lài)注入多種類(lèi)型數(shù)據(jù)的文章就介紹到這了,更多相關(guān)Spring依賴(lài)注入內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • SpringMVC如何接收參數(shù)各種場(chǎng)景

    SpringMVC如何接收參數(shù)各種場(chǎng)景

    這篇文章主要介紹了SpringMVC如何接收參數(shù)各種場(chǎng)景,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-11-11
  • 基于java Springboot實(shí)現(xiàn)教務(wù)管理系統(tǒng)詳解

    基于java Springboot實(shí)現(xiàn)教務(wù)管理系統(tǒng)詳解

    這篇文章主要介紹了Java 實(shí)現(xiàn)簡(jiǎn)易教務(wù)管理系統(tǒng)的代碼,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-08-08
  • Java如何將String轉(zhuǎn)換成json對(duì)象或json數(shù)組

    Java如何將String轉(zhuǎn)換成json對(duì)象或json數(shù)組

    這篇文章主要介紹了Java如何將String轉(zhuǎn)換成json對(duì)象或json數(shù)組,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-02-02
  • 實(shí)例講解spring boot 多線程

    實(shí)例講解spring boot 多線程

    這篇文章主要介紹了spring boot 多線程的相關(guān)資料,文中示例代碼非常詳細(xì),幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-07-07
  • 詳解java安全編碼指南之可見(jiàn)性和原子性

    詳解java安全編碼指南之可見(jiàn)性和原子性

    java類(lèi)中會(huì)定義很多變量,有類(lèi)變量也有實(shí)例變量,這些變量在訪問(wèn)的過(guò)程中,會(huì)遇到一些可見(jiàn)性和原子性的問(wèn)題。這里我們來(lái)詳細(xì)了解一下怎么避免這些問(wèn)題。
    2021-06-06
  • 流式圖表拒絕增刪改查之kafka核心消費(fèi)邏輯上篇

    流式圖表拒絕增刪改查之kafka核心消費(fèi)邏輯上篇

    這篇文章主要為大家介紹了流式圖表拒絕增刪改查之kafka核心消費(fèi)邏輯詳解的上篇,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-04-04
  • 淺談@PostConstruct不被調(diào)用的原因

    淺談@PostConstruct不被調(diào)用的原因

    這篇文章主要介紹了淺談@PostConstruct不被調(diào)用的原因及分析,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-02-02
  • 解決復(fù)制springboot項(xiàng)目后,啟動(dòng)日志無(wú)顏色的問(wèn)題

    解決復(fù)制springboot項(xiàng)目后,啟動(dòng)日志無(wú)顏色的問(wèn)題

    這篇文章主要介紹了解決復(fù)制springboot項(xiàng)目后,啟動(dòng)日志無(wú)顏色的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • 詳解springboot的多種配置方式

    詳解springboot的多種配置方式

    這篇文章主要介紹了springboot的多種配置方式,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-10-10
  • Java之TreeSet和TreeMap的兩種排序方式解讀

    Java之TreeSet和TreeMap的兩種排序方式解讀

    這篇文章主要介紹了Java之TreeSet和TreeMap的兩種排序方式解讀,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-08-08

最新評(píng)論

安福县| 易门县| 祁连县| 镇远县| 阆中市| 水富县| 凤山县| 阳高县| 昌宁县| 孟连| 中西区| 永和县| 宾川县| 肥东县| 石阡县| 宣恩县| 甘洛县| 沙湾县| 历史| 吉林市| 齐河县| 揭阳市| 九江县| 广丰县| 仁怀市| 阜康市| 临沧市| 文成县| 利津县| 申扎县| 巴彦淖尔市| 兴仁县| 敖汉旗| 合阳县| 许昌县| 新晃| 宁德市| 上栗县| 黄石市| 静宁县| 舟山市|