Spring Boot Thymeleaf 获取常量

Spring Boot Thymeleaf About 475 words

需求

使用ThymeleafHTML中获取Java代码中的常量。

常量

public interface Endpoint {

    String HOME = "/home";

    interface Api {
        String LOGIN = CONTEXT + "/login";
    }

}

Spring Expression(推荐)

使用SpEL方式获取。

IDEA没有提示内部类,会有黄色波浪线。

<div th:text="${T(z.note.lite.constant.mvc.Endpoint).HOME}"></div>
<div th:text="${T(z.note.lite.constant.mvc.Endpoint.Api).LOGIN}"></div>

OGNL

无法获取内部类。

<div th:text="${@z.note.lite.constant.mvc.Endpoint@HOME}"></div>
Views: 444 · Posted: 2023-08-24

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

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

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


Today On History
Browsing Refresh