Spring Boot Thymeleaf 获取 Bean 等容器中的对象

Spring Boot Thymeleaf About 328 words

需求

获取@Bean@Component@ConfigurationSpring自动注入到的容器对象。

${@}

使用${@}语法,获取容器中的对象。

其中,portal对象是配置类。

<title th:text="${@portal.name}"></title>

Portal代码

@Setter
@Getter
@Component // 为了在 Thymeleaf 中获取 Bean 对象时名称可以短一些
@ConfigurationProperties(prefix = "preferences.portal")
public class Portal {
    private String name;
}
Views: 364 · Posted: 2023-08-23

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh