0
我有一個包裝類,像這樣:索引進式「com.ItemBean」不支持
@NoArgsConstructor
@Data
public class ListWrapper {
public ListWrapper(List<Object> objects) {
this.objects = objects;
}
private List<Object> objects;
}
我期待來填充自定義bean的包裝。我們稱它爲一個ItemBean。
於是我有:
@GetMapping("/rentSetup")
public String setupRent(@RequestParam("companyId") Integer companyId,
Model model) {
List<Object> beans = new ArrayList<>();
ItemBean bean = new Builder()
.someProperty(something)
.build();
beans.add(bean);
ListWrapper wrapper = new ListWrapper(beans);
model.addAttribute("itemBeansWrapper", wrapper);
return "setup";
}
我想有用戶編輯屬性someProperty
在視圖。我在想,我會做:
<form th:object="${itemBeansWrapper}"
th:action="@{/setup(companyId=${companyId})}"
th:method="post">
<div th:each="bean, iterStat : ${itemBeansWrapper.objects}">
<input type="number"
th:name="${bean[__${iterStat.index}__].someProperty}">
</div>
<button type="submit"
th:name="action"
th:value="review" value="review"> Review
</button>
</form>
但是這會導致:
org.springframework.expression.spel.SpelEvaluationException: EL1027E:(pos 4): Indexing into type 'com.ItemBean' is not supported
at org.springframework.expression.spel.ast.Indexer.getValueRef(Indexer.java:176)
我在做什麼錯?
請注意,我也有我的控制器與@SessionAttributes({"companyId", "itemBeansWrapper"})
註釋,因爲我想堅持跨頁包裝了會議。
如果我離開了[__${iterStat.index}__]
,頁面編譯得很好,但我想我需要類似的東西來區分嵌套的bean。