JAVA全系列 教程
3762个小节阅读:7094.8k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
读取自定义配置时,我们可以通过@Value注解将配置文件中的值映射到一个Spring管理的Bean的字段上,用法如下:
配置文件
xxxxxxxxxx
email: itbaizhan@sxt.com
my1:
email: itbaizhan@sxt.com
password: itbaizhan
city1:
- beijing
- shanghai
- tianjin
- chongqing
sxt:
- address: beijing
mobile: 13888888888
email: bjsxt@sxt.com
- address: shanghai
mobile: 13777777777
email: shsxt@sxt.com
- address: guangzhou
mobile: 13666666666
email: gzsxt@sxt.com
读取配置文件数据:
xxxxxxxxxx
@Controller
public class YmlController1 {
@Value("${email}")
private String email;
@Value("${my1.password}")
private String password;
@Value("${city1[0]}")
private String city1;
@Value("${sxt[1].mobile}")
private String mobile;
@RequestMapping("/yml1")
@ResponseBody
public String yml1(){
return email+":"+password+":"+city1+":"+mobile;
}
}
@Value只能映射简单数据类型,不能将yaml文件中的对象、集合映射到属性中。
1. 使用注解可以将配置文件中的值映射到Bean的属性中
A @Import
B @Value
C @ConfigurationProperties
D @SpringBootApplication
答案
1=>B