
上QQ阅读APP看书,第一时间看更新
3.4 读取资源文件
SpringBoot项目中的资源文件会统一在application.yml配置文件中定义。当页面需要使用的时候,可以像输出属性一样完成,唯一的区别是需要通过“#{key}”的形式来获取资源内容。
1.【mldnboot-thymeleaf项目】在application.yml配置文件中定义资源文件配置。

2.【mldnboot-thymeleaf项目】在Messages.properties配置文件里面定义资源内容。

3.【mldnboot-thymeleaf项目】要读取资源文件,需要动态页面的支持。在Thyemeleaf Controller控制器中建立一个新的方法,用于跳转到前端页面。

4.【mldnboot-thymeleaf项目】在src/main/view/templates/message目录中创建message_value.html页面,用于读取资源文件内容并进行显示。

在Thyemeleaf模板页面中直接使用资源的key获取资源信息,页面运行效果如图3-6所示。

图3-6 Thyemeleaf模板页面读取资源文件