欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

Student實(shí)體類

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í)體類

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ù)類型有:一般類型、對象、數(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">
        <!--一般類型-->
        <property name="id" value="1"/>
        <property name="name" value="tom"/>
        <!--對象-->
        <property name="studentClass" ref="studentClass1"/>
        <!--數(shù)組-->
        <property name="books">
            <array>
                <value>Java編程思想</value>
                <value>MySQL必知必會</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>

測試

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依賴注入多種類型數(shù)據(jù)的文章就介紹到這了,更多相關(guān)Spring依賴注入內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • java中的內(nèi)部類內(nèi)部接口用法說明

    java中的內(nèi)部類內(nèi)部接口用法說明

    這篇文章主要介紹了java中的內(nèi)部類內(nèi)部接口用法說明,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • Springboot項(xiàng)目基于Devtools實(shí)現(xiàn)熱部署步驟詳解

    Springboot項(xiàng)目基于Devtools實(shí)現(xiàn)熱部署步驟詳解

    這篇文章主要介紹了Springboot項(xiàng)目基于Devtools實(shí)現(xiàn)熱部署,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-06-06
  • java操作oracle數(shù)據(jù)庫示例

    java操作oracle數(shù)據(jù)庫示例

    這篇文章主要介紹了java操作oracle數(shù)據(jù)庫示例,需要的朋友可以參考下
    2014-04-04
  • Mybatis的xml文件時間范圍條件查詢方式

    Mybatis的xml文件時間范圍條件查詢方式

    這篇文章主要介紹了Mybatis的xml文件時間范圍條件查詢方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • mybatis于xml方式和注解方式實(shí)現(xiàn)多表查詢的操作方法

    mybatis于xml方式和注解方式實(shí)現(xiàn)多表查詢的操作方法

    在數(shù)據(jù)庫中,單表的操作是最簡單的,但是在實(shí)際業(yè)務(wù)中最少也有十幾張表,并且表與表之間常常相互間聯(lián)系,本文給大家介紹mybatis于xml方式和注解方式實(shí)現(xiàn)多表查詢的操作方法,感興趣的朋友一起看看吧
    2023-12-12
  • Java實(shí)現(xiàn)解析第三方接口返回的json

    Java實(shí)現(xiàn)解析第三方接口返回的json

    在實(shí)際開發(fā)過程中,免不了和其他公司進(jìn)行聯(lián)調(diào),調(diào)用第三方接口,這個時候我們就需要根據(jù)對方返回的數(shù)據(jù)進(jìn)行解析,獲得我們想要的字段,下面我們就來看看具體有哪些方法吧
    2024-01-01
  • SpringBoot整合JDBC的實(shí)現(xiàn)

    SpringBoot整合JDBC的實(shí)現(xiàn)

    這篇文章主要介紹了SpringBoot整合JDBC的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • mybatis日志打印的兩款I(lǐng)DEA插件推薦

    mybatis日志打印的兩款I(lǐng)DEA插件推薦

    這篇文章主要給大家推薦介紹了關(guān)于mybatis日志打印的兩款I(lǐng)DEA插件,文中通過圖文以及實(shí)例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用mybatis具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2023-04-04
  • 詳解Java的Hibernate框架中的List映射表與Bag映射

    詳解Java的Hibernate框架中的List映射表與Bag映射

    這篇文章主要介紹了Java的Hibernate框架中的List映射表與Bag映射,Hibernate是Java的SSH三大web開發(fā)框架之一,需要的朋友可以參考下
    2015-12-12
  • JAVA冒泡排序和二分查找的實(shí)現(xiàn)

    JAVA冒泡排序和二分查找的實(shí)現(xiàn)

    本文詳細(xì)介紹了JAVA冒泡排序和二分查找的實(shí)現(xiàn),雖然這兩種算法比較簡單,但是確實(shí)我們必須需要掌握的。下面來看看。
    2016-07-07

最新評論