@ConfigurationProperties配置绑定

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
 
@Component//组件加入容器中
@ConfigurationProperties(prefix = "person")//Person中的属性与配置文件中person前缀下所有属性一一对应
public class Person {
    private String name;
    private int age;
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public int getAge() {
        return age;
    }
 
    public void setAge(int age) {
        this.age = age;
    }
}

  

 

 

1
2
3
4
5
6
7
8
9
10
11
@RestController
public class Demo {
    @Autowired
    Person person;
 
    @GetMapping("/test")
    public String test(){
 
        return person.getName();
    }
}

  

 

posted @   iTao0128  阅读(27)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示