![](https://img-blog.csdnimg.cn/img_convert/949f5513afe20c8f578d57c9333c3d8b.png)
![](https://img-blog.csdnimg.cn/img_convert/216e5515cbc0bbff59084e06dac1d5cd.png)
application.properties就是boot使用的配置文件,通过键值对配置对应属性,写入:
server.port=80(写port就会有提示),之后不用写8080就能访问了
![](https://img-blog.csdnimg.cn/img_convert/66141aaab3672f16e680d1df6040b0f0.png)
在springboot官网下有键值属性文档
![](https://img-blog.csdnimg.cn/img_convert/3dd89b572a92825c01e11051e8b6cf54.png)
![](https://img-blog.csdnimg.cn/img_convert/df83f557c2a9abb81e053f187d4144f2.png)
点进去后即可看到
如果需要配置的太多了怎么办?
![](https://img-blog.csdnimg.cn/img_convert/5158cad9bebe4a468eb5606e82fb1e5d.png)
![](https://img-blog.csdnimg.cn/img_convert/5ecbcba9df34d802e68cfb0632f67914.png)
创建application.yml后把原来的application.properties放入创建的bak中,在application.yml中写入
![](https://img-blog.csdnimg.cn/img_convert/94e2c99d1c22781bd90b04fa46194c01.png)
这就是yml格式,81前面的空格不能去掉
还有一种yaml格式
![](https://img-blog.csdnimg.cn/img_convert/0d31d13092ff41490b67a0d10404cd5c.png)
在现代企业中推荐使用yml格式
如果三个文件共存,properties>yml>yaml
yaml不弹提示的原因:
idea不认为yaml是配置文件,要让yaml变成配置文件
打开Project Structure
![](https://img-blog.csdnimg.cn/img_convert/21f9413e383273674a4aa2423e07465b.png)
![](https://img-blog.csdnimg.cn/img_convert/e08d5e17dffe0e803f8d174a7d865f7e.png)
这里我这个版本的idea已经自动给我配置好了yaml,如果没有点加号添加就可以了
![](https://img-blog.csdnimg.cn/img_convert/eb5ba902599a9b3772e63c23a0e65cdf.png)
![](https://img-blog.csdnimg.cn/img_convert/97db563084baa95f624c09490d7c1f26.png)
![](https://img-blog.csdnimg.cn/img_convert/303580c112196962dccbe2d83dfc05ab.png)
![](https://img-blog.csdnimg.cn/img_convert/0c9cca57eb0230a2d5291ee0cbb06dc2.png)
![](https://img-blog.csdnimg.cn/img_convert/19fbda53e134971a2041c776b21ce24d.png)
![](https://img-blog.csdnimg.cn/img_convert/8123b5efed419f154d28c4c9d683f3d5.png)
如何读取:
![](https://img-blog.csdnimg.cn/img_convert/98ba4a50baf46477adb991c930ae09aa.png)
多级数据呢?
![](https://img-blog.csdnimg.cn/img_convert/a43ec90fd21a61f3bd00c7bc56f21175.png)
数组呢?
![](https://img-blog.csdnimg.cn/img_convert/0faf76132b788387a5e20cf7eac5c4c5.png)
数组里的多级数据呢?
![](https://img-blog.csdnimg.cn/img_convert/f827bd1ebfb6684e26ea5f12592a8bd5.png)
![](https://img-blog.csdnimg.cn/img_convert/c59d9516c1024b46c4477e7983ce2741.png)
数据之间要相互引用怎么办?
![](https://img-blog.csdnimg.cn/img_convert/e4b0de4d2d184f3596a2b5f0318daa00.png)
![](https://img-blog.csdnimg.cn/img_convert/099a970b7ca2e6a3ff01691d4898f502.png)
一个变量加载配置文件所有属性
![](https://img-blog.csdnimg.cn/img_convert/d6e3d5fd03fb001f3a8b58d9e42c622e.png)