Thymeleaf/Spring MVC - How do you nest variables/expressions in a Link expression?

前端 未结 1 496
栀梦
栀梦 2020-12-17 19:01

For example, my controller method in Spring does this:

model.addAttribute(\"view_name\", \"foobar\")

And I\'m trying to do this in my Thyme

1条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-17 19:34

    Since you are not starting the url rewrite with an expression (e.g. ${...}, #{...}, |...|, __...__, 'quoted string', ...), Thymeleaf will consider the whole expression as a String and not execute any of the inner expressions.

    The following example would work because it starts with an expression.

    @{${attribute}}
    

    For your example you have the following possibilities

    Literal substition (preferred method)

    You can do literal substitions in a String with the pipeline syntax (|).

    
    

    String concatenation

    
    

    0 讨论(0)
提交回复
热议问题