zoukankan      html  css  js  c++  java
  • SpringBoot目录文件结构总结(5)

    1、目录

      src/main/java :存放java代码

      src/main/resources

        static:存放静态文件,比如css、js、image(访问方式 http://localhost:8080/js/main.js)

        templates:存放静态页面jsp,html,tpl

        config:存放配置文件application.properties

        resources:

      

    2、静态文件加载顺序:Spring Boot默认依次从:META/resources > resources >static >public > 如果存在访问的资源则返回,否则报错!

    3、引入依赖 Thymeleaf

      <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-thymeleaf -->
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
      </dependency>

      新建controller映射过去,例如404错误页面

    package cn.xiaobing.demo.controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    @Controller
    public class FailController {
        
        @RequestMapping(value = "/v1/fail")
        public Object fail() {        
            return "404";
        }
    }

    启动项目:

     访问映射地址:

     4、static:存放静态文件,比如css、js、image(访问方式 http://localhost:8080/image/500.png)

     启动项目:

     5、自定义路径访问如

     新建配置文件:application.properties

    spring.resources.static-locations = classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/testCustom/

    启动项目:

      .   ____          _            __ _ _
     /\ / ___'_ __ _ _(_)_ __  __ _    
    ( ( )\___ | '_ | '_| | '_ / _` |    
     \/  ___)| |_)| | | | | || (_| |  ) ) ) )
      '  |____| .__|_| |_|_| |_\__, | / / / /
     =========|_|==============|___/=/_/_/_/
     :: Spring Boot ::        (v2.0.1.RELEASE)

    访问资源地址:

     

    6、更多学习请spring官网查询

    7、不足之处,后续补充!

  • 相关阅读:
    如何提高技术素养
    spoolsv.exe 无法启动
    太阳高度角和方位角的计算
    树莓派 3 alsa 声卡驱动
    PHP 7 Xdebug 深深的坑
    java 线性规划 和lingo 比较
    Python Microsoft Visual C++ Compiler Package for Python 2.7
    Node debug
    angular 调试 js (分 karms protractor / test e2e unit )
    hbase scan 的例子
  • 原文地址:https://www.cnblogs.com/xiaozhaoboke/p/13160834.html
Copyright © 2011-2022 走看看