Url Spring MVC:路径变量{studentId}未正确显示
这真让我困惑。 使用一个路径变量Url Spring MVC:路径变量{studentId}未正确显示,url,spring-mvc,path-variables,Url,Spring Mvc,Path Variables,这真让我困惑。 使用一个路径变量{studentId}的值代替正确的URL: “”(其中25是路径变量{studentId}的值) 我在我的URL中得到: “” 这是我的控制器方法,用于显示一些测试页面,工作正常: @RequestMapping(value="/{studentId}/activity/add", method = RequestMethod.GET) public String getForm(@PathVariable Integer studentId, Mode
{studentId}
的值代替正确的URL:
“”(其中25是路径变量{studentId}
的值)
我在我的URL中得到:
“”
这是我的控制器方法,用于显示一些测试页面,工作正常:
@RequestMapping(value="/{studentId}/activity/add", method = RequestMethod.GET)
public String getForm(@PathVariable Integer studentId, Model model) {
StudentActivityDTO studentActivityDTO = new StudentActivityDTO();
Student student = studentService.get(studentId);
studentActivityDTO.setStudent(student);
studentActivityDTO.getActivity().setEssayFlag("Essay");
model.addAttribute("studentActivityDTO", studentActivityDTO);
model.addAttribute("courseList", courseService.getAll());
model.addAttribute("teacherList", teacherService.getAll());
return "testPage";
}
这是发生问题的后控制器方法:
@RequestMapping(value="/{studentId}/activity/add", method = RequestMethod.POST)
public String postForm(@ModelAttribute("studentActivityDTO") StudentActivityDTO studentActivityDTO,
@PathVariable Integer studentId,
Model model) {
logger.debug("Received request to add new activity to student");
Activity activity = studentActivityDTO.getActivity();
activityService.add(studentId, activity);
return "success/addActivitySuccess";
}
在第一种情况下,@PathVariable
工作正常,在第二种情况下,它会出现以下错误:
Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer'; nested exception is java.lang.NumberFormatException: For input string: "{studentId}"
URL中没有{studentId}
的某些值,而是得到字符串“{studentId}”
有人能告诉我为什么吗
更新:这是jsp页面的重要部分(这是一个相当大的页面):
...
可能是您想要的
<c:url var="studentUrl" value="/essays/main/student/${studentActivityDTO.student.id}/activity/add" />
我不明白。你在哪里生成这个URL?@SotiriosDelimanolis我从这个URL开始作为入口点:当我在应用程序中导航时,当我点击submit按钮时,我得到了一个错误的URL,其中有字符串{studentId}。在我按下“提交”按钮之前,一切正常。因为问题出在post控制器方法中,请向我们显示发送表单的JSP页面以及如何创建表单标记的“操作”属性。@t0mppa我已更新了我的帖子。
<c:url var="studentUrl" value="/essays/main/student/${studentActivityDTO.student.id}/activity/add" />