我有一个基本的 SpringBoot 2.0.5.RELEASE 应用程序。使用 Spring Initializer、JPA、嵌入式 Tomcat、Thymeleaf 模板引擎,并打包为可执行 JAR 文件。我有一个只读的选择对象,<select id="selectInvoiceId" th:field="*{invoice}" th:disabled="${resto.id != null}" > <option value="0">PLEASE SELECT AN INVOICE</option> <option th:each="invoice : ${invoices}" th:value="${invoice.id}" th:text="${invoice.symbol}"> </option></select>在控制器中我有@RequestMapping(value = { "/save" }, method = RequestMethod.POST)public String saveWallet(@Valid @ModelAttribute("wallet") WalletPayload walletPayload, BindingResult bindingResult) { ..}在 WalletPayload 对象中,我有:@NotNullprivate Invoice invoice;然后我在验证中总是出错,因为发票为空,我想知道只读对象是否有解决方法我试过这个,但我仍然有错误:@RequestMapping(value = { "/save" }, method = RequestMethod.POST) public String saveWallet(@Valid @ModelAttribute("wallet") WalletPayload walletPayload, BindingResult bindingResult) { LOG.debug("WalletPayload walletPayload [ " + walletPayload + " ]"); if (walletPayload.getId() != null) { Invoice fakeInvoine = new Invoice("fake-inv"); fakeInvoice.setId((long)-1); walletPayload.setInvoice(fakeInvoice); } if (bindingResult.hasErrors()) { return serverContextPath + WALLET_LIST_VIEW_NAME; }我也尝试使用只读,但它没有出现在选择对象上
添加回答
举报
0/150
提交
取消