【发布时间】:2021-01-14 03:46:12
【问题描述】:
我只想为 /show-owner/{id} 指定获取请求,但每次在 URL 中添加另一个路径时,我都会收到 404 not found 错误,我必须提供完整路径才能使其正常工作。
在这种情况下,最好的方法是什么?
@GetMapping(value = {"/show-owner/{id}", "/show-item/show-owner/{id}",
"/show-user/user-items-table/show-item/show-owner/{id}",
"/show-user/user-items-table/show-item/show-owner/user-items-table/{id}",
"/show-owner/user-items-table/show-item/show-owner/{id}",
"/user-items-table/show-item/show-owner/{id}"})
public ModelAndView displayOwnerByItemId(@PathVariable String id) {
try {
UserDto user = userDtoMapper.toDto(itemService.getItemById(id).getOwner());
ModelAndView mav = new ModelAndView("show-user");
mav.addObject("user", user);
return mav;
} catch (ItemNotFound e) {
return new ModelAndView("redirect:/items");
}
}
【问题讨论】:
-
看起来您在表单中使用了错误的路径 URL 或您调用 @GetMapping("/show-owner/{id}") 的链接。你能告诉我你从哪里调用 URL /show-owner/{id} 的 HTML 代码。
标签: java spring model-view-controller