Thymeleaf 在对象上的列表中多选
我正在使用 Thymeleaf 和 Spring MVC,我想做这样的多重选择:
<form action="#" th:object="${promotion}" th:action="@{/promotion/add}" method="post">
<select th:field="*{products.id}" th:value="*{products.id}" multiple="multiple" >
<optgroup th:each="c : ${categories}" th:label="${c.name}">
<option th:each="p : ${c.products}" th:value="${p.id}" th:text="${p.name}" />
</optgroup>
</select>
</form>
Run Code Online (Sandbox Code Playgroud)
我有这个对象的形式
public class Promotion implements Serializable{
private static final long serialVersionUID = 1L;
private int id;
private String name;
private List<PromoProduct> products;
}
public class PromoProduct implements Serializable {
private static final long serialVersionUID = 1L;
private int id;
private List<Integer> products;
private int amount;
}
Run Code Online (Sandbox Code Playgroud)
使用此代码,我收到以下错误消息:
org.springframework.web.util.NestedServletException: …
Run Code Online (Sandbox Code Playgroud) chart.js ×1
css ×1
java ×1
javascript ×1
jquery ×1
list ×1
radar-chart ×1
select ×1
spring-mvc ×1
thymeleaf ×1