2017-11-27 12 views
0

저는 스프링 MVC의 초보자이며 실수를합니다 ... 그래서 버튼과 Thymeleaf로 동적 URL을 위조하고 싶지만 작동하지 않습니다. 따옴표 또는 유사한 이스케이프에 대한 생각, $ {key}는 평가에 맞지 않습니까? 여러분의 도움과 인내 일반적으로onclick thymeleaf 동적 URL 매개 변수

답변

1

에 대한

<tr th:each="key: ${serverBean.getServerB().keySet()}"> 
    <td> 
     <span th:text="${serverBean.getServerB().get(key)}" /> 
    </td> 
    <td align="center"> 
     <span th:text="${key}" /> 
    </td> 
    <td th:if="${protoStatusBean.getStatus(key)}" bgcolor="lime" /> 
    <td th:unless="${protoStatusBean.getStatus(key)}" bgcolor="red"/> 
    <td> 
     <button th:onclick="window.location.href='/update?server=${key}'"> 
      <img src="./images/wrench.png" height="15" width="15"> 
     </button> 
    </td> 
</tr> 

덕분에, 당신은 작은 따옴표 텍스트 리터럴을 둘러싸고해야합니다. 귀하의 예제가 작동하려면, 그것은 다음과 같아야합니다

말했다되고 그건
th:onclick="'window.location.href=\'/update?server=' + ${key} + '\''" 

, 문자열 연결이 가장 보이는 생각에 따라 작업을 얻을 수있는 다양한 방법이 있습니다.

th:onclick="|window.location.href='/update?server=${key}'|" 
th:onclick="${'window.location.href=''/update?server=' + key + ''''}" 
th:onclick="|window.location.href='@{/update(server=${key})}'|" 
+0

고맙습니다. –