How to get the request context in a freemaker template in spring

前端 未结 2 1471
情歌与酒
情歌与酒 2020-12-15 17:26

How to get the request context path in freemarker template when using with spring?

My view resolver is like this

    

        
2条回答
  •  北荒
    北荒 (楼主)
    2020-12-15 17:34

    If your requirement is to fetch the Context Path in your FTL view then Spring provides a better alternate - First import spring.ftl in your view

    <#import "/spring.ftl" as spring />
    

    Then use macro @spring.url for the URL which you want to make context aware -

  • History
  • This is very much similar to -

  • History
  • Where rc is defined in viewResolver

    XML based configuration

    
    

    or Spring Boot style configuration (aplication.yml)

    spring.freemarker.request-context-attribute: rc
    

提交回复
热议问题