thymeleaf 獲取項目路徑


<p th:text=${salecode}></p>

<a th:href="${#httpServletRequest.getScheme()+'://'+#httpServletRequest.getServerName()+':'+#httpServletRequest.getServerPort()+#httpServletRequest.getContextPath()+'/icon/'+salecode } "
></a>

效果圖如下:

 

插入一段本地不需要加上項目名稱,在正式環境下服務器下需要加上項目名稱的判斷,免得本地和服務器上都改來改去,有時候忘記改了,就gg了:

<a class="item" th:each="taopiao,u : ${list}" th:if="${#httpServletRequest.getServerPort()} ne 8080" th:href="'/fastbuytickets/purchase?id='+${taopiao.productId}">
        服務器調測
</a>
<a class="item" th:each="taopiao,u : ${list}" th:if="${#httpServletRequest.getServerPort()} eq 8080" th:href="'/purchasetest?id='+${taopiao.productId}">
        本地調測
</a>

 

 

自己當筆記用,不給壞人用


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM