Thymeleaf + spring dynamic replace

后端 未结 5 1774
花落未央
花落未央 2021-02-06 00:47

Is it possible to create a dynamic replace in Thymeleaf?

I have the following controller:

@Controller
public class LoginController {

    @RequestMapping         


        
5条回答
  •  隐瞒了意图╮
    2021-02-06 01:16

    In Thymeleaf 3.0, the following solution has worked for me:

    (Note however, that I use it with fixed name of the fragment and dynamic name of the template, so the parantheses around :: (${template}) might be optional.)

    The solution is inspired by documentation for Thymeleaf in https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#fragment-specification-syntax

    Both templatename and selector in the above examples can be fully-featured expressions (even conditionals!) like:

    Note again how the surrounding ~{...} envelope is optional in th:insert/th:replace

提交回复
热议问题