gpt4 book ai didi

java - 使用 @PathVariable 重定向到另一个 Controller

转载 作者:行者123 更新时间:2023-11-30 06:47:35 24 4
gpt4 key购买 nike

如何在重定向中使用路径变量重定向到另一个 Controller 。我尝试了以下方式,但出现此错误:

java.lang.IllegalArgumentException: Model has no value for key 'formId'

我是如何实现的:

Long formId = drugType.getFormId();
view = "redirect:/pub/req/customForm/view/{formId}";

并被 Controller 接收到:

@RequestMapping(method = RequestMethod.POST,  value = "/pub/req/customForm/view/{formId}")
String completeCustomForm(@PathVariable Long formId,
@Valid @ModelAttribute CustomFormLayout customFormLayout,
BindingResult errors, HttpServletRequest request, Model model,
RedirectAttributes attr) {

关于如何使用 formId 值重定向到这个 Controller 有什么想法吗?

最佳答案

尝试应用参数:

Long formId = drugType.getFormId();
view = "redirect:/pub/req/customForm/view/"+formId;

关于java - 使用 @PathVariable 重定向到另一个 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45751592/

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