2015-06-05 109 views
0

在我的Spring MVC应用程序中,除了一个以外,我的所有RequestMapping都正确映射。我无法弄清楚为什么这是PageNotFound错误。对于方法addSatisfaction,我得到PageNotFound - No mapping found for HTTP request with URI [/CCHPWeb/heart2heart/feedback/102/resolution/satisfaction] in DispatcherServlet with name 'dispatcher'PageNotFound - 在名为'dispatcher'的DispatcherServlet中找到URI为[]的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("/"); 
    } 
} 
+0

方法级上的RequestMappings不应该有前导“/” – Nitek

回答

1

你不需要这里$:

/${feedbackId}/resolution/satisfaction 

改变它

/{feedbackId}/resolution/satisfaction 

$代表正则表达式中'结束字符串(或行)'。我不认为你真的需要它在路径映射中,因为它对整数feedbackId没有意义。

+0

这是正确的。我直接从HTML复制链接,并获得了$符号。 – khateeb

0

@khateeb,May问题与web.xml请找到下面的web.xml内容。 <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>

+0

我不使用'web.xml'。我使用基于Java的配置。我用它更新了我的问题。它与你的配置类似。 – khateeb

+0

试着用@Juned Ahsan评论。通常我们可能不会像这样改变/ $ {feedbackId}/resolution/satisfaction// feedbackId}/resolution/satisfaction –

相关问题