johnsonshu
V2EX  ›  问与答

关于 thymeleaf 里调用类的 static method

  •  
  •   johnsonshu · Oct 20, 2021 · 1495 views
    This topic created in 1659 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
        1
    yangyaofei  
       Oct 20, 2021 via Android   ❤️ 1
    SpEl ? testutil 写个 bean,然后就可以直接调用了
    cyndihuifei
        2
    cyndihuifei  
       Oct 21, 2021
    当然是前后端分离啦
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1245 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 17:25 · PVG 01:25 · LAX 10:25 · JFK 13:25
    ♥ Do have faith in what you're doing.