鉴于我具有带有映射的MVC端点:
@RequestMapping
public String eventHistory(final Model model,
@PageableDefault(sort = {"id"}, direction = DESC) final Pageable pageable,
final EventHistoryFilter eventHistoryFilter) {
...
model.addAttribute("eventHistoryFilter", eventHistoryFilter);
}
其中EventHistoryFilter
是:
final class EventHistoryFilter {
private Long eventId;
private String eventType;
private String eventDateFrom;
private String eventDateTo;
...
}
在百里香模板中,我想用参数构造URL,例如:
th:href="@{/event-history(page=${page.number-1},eventId=${eventHistoryFilter.eventId},eventType=${eventHistoryFilter.eventType},eventDateFrom=${eventHistoryFilter.eventDateFrom},eventDateTo=${eventHistoryFilter.eventDateTo})}"
如何一次性将多个参数添加到URL中?
我在这里找不到它:https://www.thymeleaf.org/doc/articles/standardurlsyntax.html#adding-parameters
我想避免一个一个地指定每个参数。
编辑: 我尝试使用https://www.thymeleaf.org/doc/tutorials/3.0/thymeleafspring.html#building-uris-to-controllers
String url = MvcUriComponentsBuilder.fromMappingName("EHE#eventHistory").arg(2, eventHistoryFilter).build();
但已解析的URL不包含任何请求参数。
和百里香对应物:
th:href="${#mvc.url('EHE#eventHistory').arg(2,__${eventHistoryFilter}__).build()}"
评估期间失败。