【SpringBoot】.ymal

30 阅读1分钟

语法格式

image.png

image.png

image.png

读取配置信息

方式1:@Value("${属性名})

image.png

方式2:使用Environment.getProperty("属性名")

image.png

把对应属性封装成对象

enterprise:
  name: 
  age: 
  subject:
    - 
    - 
    - 
@Component
@ConfigurationProperties(prefix = "enterprise")
public class Enterprise {
    ...
}
//*Controller
@Autowired
private Enterprise enterprise;