【发布时间】:2016-10-03 20:36:50
【问题描述】:
我正在使用 Thymeleaf 和 Spring Boot。 我的 html 中有一个使用 thymeleaf 的链接:
<a th:href="@{/fleetcompany/workorders/proposals/selected/{id}(id=${proposal.bidID})/{id2}(id2=${proposal.workID})}">SELECT</a>
当我只传递一个值时,它可以工作,但是当我传递两个值时,它没有。它有错误:
Failed to convert value of type [java.lang.String] to required type [java.lang.Long]; nested exception is java.lang.NumberFormatException: For input string: "{id}(id=${proposal.bidID})"
这是我的 MVC 控制器:
@RequestMapping(value={"/workorders/proposals/selected/{bidID}/{woNumber}"}, method = RequestMethod.GET)
public String selectProposal(Model model,
final RedirectAttributes redirectAttributes,
@PathVariable("bidID") Long bidID,
@PathVariable("woNumber") Long woNumber){
String selected = "Selected";
String notSelected = "Not Selected";
String orderStatus = "Pending";
bidServiceInterface.updateSelectedBidStatus(selected, bidID);
bidServiceInterface.updateNotSelectedBidStatus(notSelected, woNumber);
woServiceInterface.updateWorkOrderStatus(orderStatus, woNumber);
return "redirect:/fleetcompany/workorders";
}
我知道我所有的数据类型都是正确的,因为当我交换两个 id 时它可以工作,但当我同时使用它们时却不行。
【问题讨论】:
-
当您收到错误消息时,它使用的实际 url 是什么?我还想知道 /selected/1234/1234 时的路径变量是否正在转换为 1234/1234,因此它无法转换为 long。你能试试/selected/1234/workorder/1234吗?
-
刚刚在一个示例项目中尝试过,两个相邻的路径变量对我来说效果很好。让我觉得应该存在的数字中有一些东西。你能发布它要去的网址吗?
-
@blur0224 我解决了。我不知道我只能用一个初始化器来做。像这样。 选择一个>。感谢您的宝贵时间。
-
@Lester:你可以把你所做的写下来作为答案,然后接受它,这样未来的人也可以学习。
标签: html spring spring-mvc spring-security thymeleaf