第一种 freemark的
1.resources下面的templates下增加html页面(因为是模板)
2.然后配置文件增加如下
(#FreeMarkerViewResolver的优先级大于InternalResourceViewResolver的优先级,所以同时存在的话,会返回freemarker视图)
server.port=8888
server.servlet.context-path=/test
spring.freemarker.suffix=.html
spring.freemarker.content-type=text/html
spring.freemarker.template-loader-path=classpath:/templates/
3.pom增加freemark依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
4.增加映射
@Controller
public class PageController {
@RequestMapping ("/index.html")
public String index(HttpServletRequest request, HttpServletResponse response) {
return "index";
}
@RequestMapping ("/{module}/{page}.html")
public String modules(@PathVariable String module, @PathVariable String page, HttpServletRequest request,
HttpServletResponse response) throws IOException {
if (module == null || page == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
return module + "/" + page;
}
搞定!
http://localhost:8888/test/xxx.html
第二种,简单的
1、配置文件
spring.mvc.view.suffix=.html spring.mvc.view.prefix=/
2、resources下的static下增加html控件(因为是静态页面)
3、增加映射
@Controller public class PageController { @RequestMapping ("index") public String index(HttpServletRequest request, HttpServletResponse response) { return "index"; } 搞定!
http://localhost:8080/index.html