gpt4 book ai didi

java - 消息 参数条件 "rejection"不满足实际请求参数 : reason={}

转载 作者:行者123 更新时间:2023-12-02 04:33:33 28 4
gpt4 key购买 nike

我的 Thymeleaf 模板和/或 Controller 有问题。

模板如下所示:

<div align="left">
<form action="#" th:action="@{/rejection/{invoiceId}(invoiceId=${invoiceId})}" th:object="${rejection}" method="post">
<ul class="form-style-1">
<li>
<label>Powód odrzucenia:<span class="required">*</span></label>
<input type="text" th:field="*{reason}" id="reason" required>
</li>
<li>
<input type="submit" value="Wyślij powód odrzucenia protokołu"/>
</li>
</ul>
</form>
</div>

以下是 Controller 方法:

@GetMapping(params = "invoiceId", path = "/reject")
public String reject(@RequestParam("invoiceId") String invoiceId, @CurrentUser Contractor contractor, Model model) {
InvoiceData invoiceData = invoiceDataRepository.findById(invoiceId).get();
invoiceData.setStatus(StatusEnum.REJECTED.toString());
invoiceDataRepository.save(invoiceData);
Rejection rejection = new Rejection(invoiceId, null);
model.addAttribute("contractor", contractor);
model.addAttribute("rejection", rejection);
return "reject";
}

@PostMapping(params = "rejection", path = "/rejection")
public String rejection(@RequestParam("rejection") Rejection rejection, @CurrentUser Contractor contractor, Model model) {
InvoiceData invoiceData = invoiceDataRepository.findById(rejection.getInvoiceId()).get();
model.addAttribute("contractor", contractor);
model.addAttribute("rejection", rejection);
emailService.sendRejectionMessage(contractor.getEmail(), invoiceData, rejection.getReason());
logger.info("Invoice number "+ invoiceData.getInvoiceNumber() +" with ID " + invoiceData.getId() + " rejected for Contractor with ID " + contractor.getId());
return "index";
}

当我尝试从拒绝模板发送数据时,出现错误:

2019-06-12 15:04:13.451  WARN 23678 --- [nio-8080-exec-9] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.bind.UnsatisfiedServletRequestParameterException: Parameter conditions "rejection" not met for actual request parameters: reason={some text here}]

这是拒绝类:

@Data
@AllArgsConstructor
public class Rejection {

private String invoiceId;
private String reason;

}

我做错了什么?请求参数是一个 Rejection 对象,而不仅仅是 Rejection 字段reason...

最佳答案

您看到该错误的原因是您的 @PostMapping 中有 params = "rejection"。它需要一个名为 rejection 的参数,但您尚未提供任何参数。只需删除它,除非您有特定的原因需要它。

关于java - 消息 参数条件 "rejection"不满足实际请求参数 : reason={},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56563043/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com