spring boot 直接返回HTML

@Controller
public class HomeController {
    @RequestMapping(value = {"","/home"},method = RequestMethod.GET)
    public String home(){
        return "home";
    }
}


要直接返回HTML, 并且访问URL 时要调用想要的页面,可以thymeleaf或者freemarker,但是直接返回html,


资源文件的约定目录结构 

Maven的资源文件目录:/src/Java/resources 
spring-boot项目静态文件目录:/src/java/resources/static 
spring-boot项目模板文件目录:/src/java/resources/templates 
spring-boot静态首页的支持,即index.html放在以下目录结构会直接映射到应用的根目录下:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. classpath:/META-INF/resources/index.html    
  2. classpath:/resources/index.html    
  3. classpath:/static/index.html    
  4. calsspath:/public/index.html    

在spring-boot下,默认约定了Controller试图跳转中thymeleaf模板文件的的前缀prefix是”classpath:/templates/”,后缀suffix是”.html” 
这个在application.properties配置文件中是可以修改的。 
如下配置可以修改试图跳转的前缀和后缀
[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. spring.thymeleaf.prefix: /templates/    
  2. spring.thymeleaf.suffix: .html    

更过有关thymeleaf中的默认这是可以查看org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties这个类的属性 。




http://blog.csdn.net/u014695188/article/details/52347318

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值