springMvc 可以进控制器 返回html No mapping found for HTTP request with URI

村头王员外 2018-09-16 11:37:08
没有分,但是非常想解决这问题

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'

/black/WEB-INF/htmlviews/hello.html在工程中是肯定存在的,为什么地址栏请求却是404呢?
...全文
515 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
verejava 2018-09-18
  • 打赏
  • 举报
回复
村头王员外 2018-09-18
  • 打赏
  • 举报
回复
dddddddddd
村头王员外 2018-09-18
  • 打赏
  • 举报
回复
这是什么???
村头王员外 2018-09-17
  • 打赏
  • 举报
回复
dd
在线急

2,100

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧