首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Springboot返回html 原

Springboot返回html 原

作者头像
克虏伯
发布2019-04-15 10:16:28
3.3K0
发布2019-04-15 10:16:28
举报

    注:Springboot的版本2.1.3.RELEASE

List-1 application.properties文件

server.port=8080
#url中,项目的前缀
server.servlet.context-path=/project


spring.mvc.view.prefix=/
spring.mvc.view.suffix=.html

    整体结构如下图1所示,html要放在static下,不是templates下

                         图1

List-2 HelloController的内容如下

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Slf4j
@Controller
public class HelloController {

    @RequestMapping(value = "/hello")
    public String index() {
        log.info("收到请求");
        return "html/hello";
    }
}

List-3 启动springboot,之后在浏览器中输入

#返回index.html的内容
http://localhost:8080/project/

#返回hello.html的内容
http://localhost:8080/project/hello

    网上很多关于模板的(Thymeleaf 、FreeMarker 等),但是我不需要,我只需要纯的html。

    index.html是springboot的默认welcome page。

Reference

  1. https://www.jianshu.com/p/eb4c0fc2dfc4
  2. https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-spring-mvc-static-content
  3. https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-spring-mvc-welcome-page

(adsbygoogle = window.adsbygoogle || []).push({});

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Reference
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档