V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
johnsonshu
V2EX  ›  问与答

关于 thymeleaf 里调用类的 static method

  •  
  •   johnsonshu · 2021-10-20 21:45:02 +08:00 · 736 次点击
    这是一个创建于 890 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    <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>
    
    第 1 条附言  ·  2021-10-21 09:59:29 +08:00

    谢谢建议,写完了。

    Java端:

    @Repository("stringUtil")
    public class StringUtil {
    

    Thymeleaf 端:

    th:href="${@stringUtil.convert2Context(room.url)}
    
    2 条回复    2021-10-21 17:18:42 +08:00
    yangyaofei
        1
    yangyaofei  
       2021-10-20 23:10:07 +08:00 via Android   ❤️ 1
    SpEl ? testutil 写个 bean,然后就可以直接调用了
    cyndihuifei
        2
    cyndihuifei  
       2021-10-21 17:18:42 +08:00
    当然是前后端分离啦
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1124 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 22:52 · PVG 06:52 · LAX 15:52 · JFK 18:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.