[SB框架]SpringBoot中對多個配置文件中的屬性進行提取的簡易方法

我們要提取一下屬性:
在這裏插入圖片描述
首先創建一個GirlProperties類
在這裏插入圖片描述

package com.springboot.properties;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * @BelongsProject: springbootideademo
 * @BelongsPackage: com.springboot.properties
 * @Author: HUANG
 * @CreateTime: 2018-11-15 21:46
 * @PROJECT_NAME: springbootideademo
 */
@Component
@ConfigurationProperties(prefix = "girl")
public class GirlProperties {
    private String cupSize;
    private Integer age;

    public String getCupSize() {
        return cupSize;
    }

    public void setCupSize(String cupSize) {
        this.cupSize = cupSize;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}

調用方式:
在這裏插入圖片描述

通過屬性調用:
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章