spring boot 直接返回HTML

  • Post author:
  • Post category:其他


@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放在以下目录结构会直接映射到应用的根目录下:



  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配置文件中是可以修改的。




如下配置可以修改试图跳转的前缀和后缀




  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




版权声明:本文为dulabing原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。