Nuñ*_*ada 3 java spring spring-mvc thymeleaf spring-boot
我有一个基本的 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>
Run Code Online (Sandbox Code Playgroud)
在控制器中我有
@RequestMapping(value = { "/save" }, method = RequestMethod.POST)
public String saveWallet(@Valid @ModelAttribute("wallet") WalletPayload walletPayload,
BindingResult bindingResult) {
..
}
Run Code Online (Sandbox Code Playgroud)
在 WalletPayload 对象中,我有:
@NotNull
private Invoice invoice;
Run Code Online (Sandbox Code Playgroud)
然后我在验证中总是出错,因为发票为空,我想知道只读对象是否有解决方法
我试过这个,但我仍然有错误:
@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;
}
Run Code Online (Sandbox Code Playgroud)
我也尝试使用只读,但它没有出现在选择对象上
readonly如果您希望发送值而您不希望用户能够对其进行编辑,则应选择使用。
使用disabled和之间存在细微差别readonly
比较
readonly项目不可编辑,但将在提交后发送。disabled项目不可编辑,一旦提交就不会发送。readonly项目是可聚焦的,而disabled一个则不是。
| 归档时间: |
|
| 查看次数: |
10091 次 |
| 最近记录: |