gpt4 book ai didi

java - PageNotFound - 在 DispatcherServlet 中未找到带有 URI [] 且名称为 'dispatcher' 的 HTTP 请求的映射

转载 作者:行者123 更新时间:2023-12-01 11:27:54 25 4
gpt4 key购买 nike

在我的 Spring MVC 应用程序中,除了一个之外,我的所有 RequestMapping 都已正确映射。我无法弄清楚为什么会出现 PageNotFound 错误。对于方法 addSatisfaction,我收到 PageNotFound - 在名为“dispatcher”的 DispatcherServlet 中未找到带有 URI [/CCHPWeb/heart2heart/feedback/102/resolution/satisfaction] 的 HTTP 请求的映射.

我的 Controller :

@Controller
@RequestMapping("/heart2heart/feedback")
public class H2HFeedbackController {

private static final Logger logger = LoggerFactory.getLogger(H2HFeedbackController.class);
private final ActivitiService activitiService;
private final Heart2HeartService heart2heartService;

@Autowired
public H2HFeedbackController(ActivitiService activitiService, Heart2HeartService heart2heartService) {
super();
this.activitiService = activitiService;
this.heart2heartService = heart2heartService;
}

@RequestMapping(value = "/${feedbackId}/resolution/satisfaction", method = RequestMethod.GET)
public String getSatisfaction(@PathVariable int feedbackId, Model model) {
Feedback feedback = new Feedback();
feedback.setId(feedbackId);
try {
feedback = heart2heartService.getFeedbackById(feedback);
if (feedback.getId() == 0) {
model.addAttribute("error", "Feedback does not exist");
model.addAttribute("status", "404 - Not Found");
return "error";
}
model.addAttribute("feedback", feedback);
} catch (Exception e) {
logger.error("Exception :: ", e);
}
return "heart2heart/closeFeedback";
}

@RequestMapping(value = "/{feedbackId}", method = RequestMethod.GET)
public String viewFeedback(@PathVariable int feedbackId, Model model) {
Feedback feedback = new Feedback();
feedback.setId(feedbackId);
try {
feedback = heart2heartService.getFeedbackById(feedback);
if (feedback.getId() == 0) {
model.addAttribute("error", "Feedback does not exist");
model.addAttribute("status", "404 - Not Found");
return "error";
}
model.addAttribute("feedback", feedback);
} catch (Exception e) {
logger.error("Exception :: ", e);
}
return "heart2heart/feedbackView";
}
}

我的WebApplicationInitializer是:

public class SiteMain implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) throws ServletException {
AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
dispatcherContext.register(MvcConfig.class);
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}

最佳答案

这里不需要 $:

/${feedbackId}/resolution/satisfaction

更改为

/{feedbackId}/resolution/satisfaction

$ 代表正则表达式中的“字符串(或行)结尾”。我认为您在路径映射中并不真正需要它,因为它对于整数 FeedbackId 没有意义。

关于java - PageNotFound - 在 DispatcherServlet 中未找到带有 URI [] 且名称为 'dispatcher' 的 HTTP 请求的映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30659642/

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