1. 程式人生 > >SpringBoot中對多個配置檔案中的屬性進行提取的簡易方法

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;
    }
}

呼叫方式:
在這裡插入圖片描述

通過屬性呼叫:
在這裡插入圖片描述