zoukankan      html  css  js  c++  java
  • springBoot项目中的static和templates文件夹

    记录是为了更好的成长!

    SpringBoot里面没有我们之前常规web开发的WebContent(WebApp),它只有src目录

    在src/main/resources下面有两个文件夹,static和templates   springboot默认  static中放静态页面,而templates中放动态页面。

    但是webapp文件夹可以有,需要配置视图解析器同样可以访问。

    1、static文件中(static文件默认是放静态资源的)

    //这样写不能访问static中index文件夹下的index.html页面    
    @RequestMapping("index")
        public String hello() {
            return "/index/index";
        }
    //这样写才能访问到
    @RequestMapping("index")
        public String hello() {
            return "/index/index.html";
        }

     2、templates文件夹(放视图模板,就是springBoot的动态页面,需要引入thymeleaf组件)

       templates文件夹中的页面需要引入thymeleaf组件之后经过控制器返回才能访问到。

    3、springBoot项目中Controller层的页面重定向问题,需要引入thymeleaf组件

        @RequestMapping("index")
        public String hello() {
            return "/index/index.html";
        }
        
       //请求test会重定向到index     
        @RequestMapping("test")
        public String test() {
            return "redirect:/index";
        }      

     4、templates文件夹中的页面中引入static文件中的资源

      编译之后static文件夹下的文件和templates文件夹下的文件其实会出现在同一个目录下,引入样式或者默认图片的时候注意

    以上内容代表个人观点,仅供参考,不喜勿喷。。。

  • 相关阅读:
    Amoeba -- 阿里巴巴工程师的开源项目之一陈思儒
    js表达式与语句的区别
    互联网公司github项目汇总
    CDN解决方案
    免费评论组件多说
    ajax同步的实现
    两种时间格式化对比
    Google Gson 使用简介
    使用XStream解析MXL文件用到的jar包---xpp3_min-1.1.3.4.O.jar和xstream-1.3.1.jar
    《Netty in Action》中文版
  • 原文地址:https://www.cnblogs.com/newbest/p/9974959.html
Copyright © 2011-2022 走看看