Thtmeleaf的URL

1,URL表达式

  1),语法

    在Thymeleaf中URL表达式语法为@{}

  2),绝对路径

    <a th:href="@{http://www.baidu.com}">绝对路径</a>

  3),相对路径

    相对于当前项目的根

    <a th:href="@{/show2}"></a>

    相对于服务器路径的根

    <a th:href="@{~/项目名/请求名}"></a>

2,在URL中转递参数

  1),普通URL传递参数

    [1]静态参数

    <a th:href="@{/show?id=1&name=zhangsan}">普通URL传递参数一</a>

    <a th:href="@{/show(id=2,name=lishi)}">普通URL传递参数二</a>

    [2]动态参数

    <a th:href="@{'/show?id='+${id}+'&name='+${name}}"></a>

    <a th:href="@{/show(id=${id},name=[${name})}"></a>

  2),在restful格式的URL中传递参数

    <a th:href="@{/show/{id}/{name}(id=200,name=zhaoliu)}"></a>

    实例:

      

 

 

      

 

     <a th:href="@{/show/{id}(id="100",name="zhaoliu")}"></a>

    实例:

      

 

 

      

 

         

 

        <a th:href="@{show/{id}(id=${id1},name=${name1})}"></a>

 

posted @ 2020-04-28 11:55  拯代码  阅读(320)  评论(0编辑  收藏  举报