Thymeleaf - 我无法使用Link th:href将两个值从HTML传递给Controller

时间:2016-06-03 17:15:57

标签: html spring spring-mvc spring-security thymeleaf

我正在使用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时它工作但不是当我同时使用它们时。

1 个答案:

答案 0 :(得分:3)

我解决了。我不知道我必须只使用一个初始化程序。像这样。

<a th:href="@{/fleetcompany/workorders/proposals/selected/{id}/{id2}(id=${proposal.‌​bidID}, id2=${proposal.woNumber})}">SELECT</a>.