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;
}
}
您的MainController在com.chat包下? –
com.chat.controller - mainController; com.chat.config - webmvcConfig –
更改映射從/像這樣開始'@RequestMapping(value =「/ welcome」,method = RequestMethod.GET)' – StanislavL