2017-08-30 15 views
0

私はスプリング構成(xmlなし)でスプリングmvcを使用します。 IDEAはコントローラコードには行きません。いくつかのヒントをお願いします。多分どこかのパスが間違っているので、@RequestMappingは動作しません。しかし、正確にどこを理解するのかわかりません。 は、ここに私のコントローラコントローラは動作しません

@Controller 
public class MainController { 

@RequestMapping(value = "/" , method = RequestMethod.GET) 
public String home() { 

    return "index"; 
} 
@RequestMapping(value = "welcome", method = RequestMethod.GET) 
public String welcome(Model m){ 
    m.addAttribute("name","lol kkeke"); 
    return "index2"; 
} 

}

WebMvcConfig

@Configuration 
@ComponentScan("com.chat") 
@EnableWebMvc 
public class WebMVCConfig extends WebMvcConfigurerAdapter { 

@Override 
public void addResourceHandlers(ResourceHandlerRegistry registry) { 
    registry.addResourceHandler("/scripts/**").addResourceLocations("/scripts/"); 
    registry.addResourceHandler("/styles/**").addResourceLocations("/styles/"); 
    registry.addResourceHandler("/images/**").addResourceLocations("/images/"); 
    registry.addResourceHandler("/fonts/**").addResourceLocations("/fonts/"); 
    registry.addResourceHandler("/pages/**").addResourceLocations("/views/"); 

} 

@Override 
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { 
    configurer.enable(); 

} 


@Override 
public void addViewControllers(ViewControllerRegistry registry) { 
    registry.addViewController("/").setViewName("/index.jsp"); 
} 

@Bean 
public InternalResourceViewResolver viewResolver() { 
    InternalResourceViewResolver resolver = new InternalResourceViewResolver(); 

    resolver.setPrefix("/"); 
    resolver.setSuffix(".jsp"); 
    resolver.setViewClass(JstlView.class); 
    return resolver; 
} 

}

+0

あなたのMainControllerはcom.chatパッケージの下にありますか? –

+0

com.chat.controller - mainController; com.chat.config -webmvcConfig –

+0

マッピングを「/RequestMapping(value = "/ welcome"、method = RequestMethod.GET)」のように変更すると、 – StanislavL

答えて

1

です..だから私は、問題を解決しました。これはコントローラパスにありました。 My Ideaは自動的にcom.chat.controllerからc.c.controllerへのパスを変更します。だから私はcom.chat.controller.Controller.classにプロジェクトの構造を再構築する;およびcom.chat.config.Configuration.class。

また、次の記事で同様の問題が見つかりました。誰かを助けることができるかもしれません! How do I map Spring MVC controller to a uri with and without trailing slash?

関連する問題