springboot 简单支持 html 页面

第一种 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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值