package com.example.demo_05.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component //将当前组件作为springboot的一个组件来使用,这样子才会纳入容器管理
@ConfigurationProperties(prefix = "emp")//对应配置文件的值,映射到这个类中,emp为配置中的前缀(1)
public class Emp {
// @Value("${emp.lastName}")对应配置文件的值,映射到这个类中,另一种映射方法(2)
private String lastName;
// @Value("#{900}")
private int age;
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "Emp{" +
"lastName='" + lastName + '\'' +
", age=" + age +
'}';
}
}