johnsonshu
V2EX  ›  问与答

关于 thymeleaf 里调用类的 static method

  •  
  •   johnsonshu · Oct 20, 2021 · 1975 views
    This topic created in 1840 days ago, the information mentioned may be changed or developed.

    上网查了一下,基本都是用下面的方法, 但是 网页代码寸土寸金的, 这种写法也太丑陋了。 有什么优雅一点的解决办法吗?

    <div th:text=”${T(com.example.demo.TestUtils).toUpperCase(‘hello world 1’)}”></div>
    <div th:text=”${T(com.example.demo.TestController).toLowerCase(‘HELLO WORLD 2’)}”></div>
    
    Supplement 1  ·  Oct 21, 2021

    谢谢建议,写完了。

    Java端:

    @Repository("stringUtil")
    public class StringUtil {
    

    Thymeleaf 端:

    th:href="${@stringUtil.convert2Context(room.url)}
    
    2 replies  •  2021-10-21 17:18:42 +08:00
    yangyaofei
    yangyaofei
    Oct 20, 2021 via Android❤️1
    1
    SpEl ? testutil 写个 bean,然后就可以直接调用了
    cyndihuifei
    cyndihuifei
    Oct 21, 2021
    2
    当然是前后端分离啦
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4746 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 09:17 · PVG 17:17 · LAX 01:17 · JFK 04:17
    ♥ Do have faith in what you're doing.