thymeleaf为输入标签设置'name''id''value'attr的值

时间:2016-07-19 02:39:12

标签: jsp thymeleaf

我在jsp文件中有一个片段,如下所示

<c:forEach var="question" items="${questionList }">
    <p>{{ question.question }}</p>

    <c:forEach var="answer" items="${question.answerList }">
        <input type="radio" name="${question.id }" id="${answer.id }" value="${answer.sequence }">
        <label for="${answer.id }">${answer.answer }</label>
    </c:forEach>

</c:forEach>

现在我使用百里香模板,我不知道如何在百里香中实施它。特别是,我不知道如何获得name的{​​{1}} attr,

input

1 个答案:

答案 0 :(得分:1)

您可以尝试使用th:with来处理百里香的局部变量,

<div th:with="questionObj=${questionList}">
    <div th:each="answer: ${questionObj}">
        <input type="radio" th:name="${questionObj.id}" 
               th:id="${answer.id}" th:value="${answer.sequence}">
        <label th:text="${answer.answer}"></label>
    </div>
</div>

参考:Local Variables