2,100
社区成员
发帖
与我相关
我的任务
分享
public class init implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(HtmlConfig.class);
ctx.setServletContext(servletContext);
ServletRegistration.Dynamic servlet = servletContext.
addServlet("dispatcher", new DispatcherServlet(ctx));
servlet.setLoadOnStartup(1);
servlet.addMapping("*.html");
servlet.addMapping("/");
}
}
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "color.gray")
public class HtmlConfig {
@Bean
public ViewResolver FreeMarkerViewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/htmlviews/");
viewResolver.setSuffix(".html");
return viewResolver;
}
}
@Controller
@RequestMapping("html")
public class HtmlContA {
@RequestMapping("/hello")
public String hellowrold() {
System.out.println("Mapping HttpRequest");
return "hello";
}
}
Mapping HttpRequest
九月 16, 2018 11:24:47 上午 org.springframework.web.servlet.PageNotFound noHandlerFound
警告: No mapping found for HTTP request with URI [/black/WEB-INF/htmlviews/hello.html] in DispatcherServlet with name 'dispatcher'