zoukankan      html  css  js  c++  java
  • spring-boot 加载本地静态资源文件路径配置

    1.spring boot默认加载文件的路径是 
    /META-INF/resources/ 
    /resources/ 
    /static/ 
    /public/ 
    这些目录下面, 当然我们也可以从spring boot源码也可以看到 
    Java代码  收藏代码
    1. private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {  
    2.         "classpath:/META-INF/resources/""classpath:/resources/",  
    3.         "classpath:/static/""classpath:/public/" };  

    所有本地的静态资源都配置在了classpath下面了, 而非在webapp下了 

    2. 
    Html代码  收藏代码
    1. <%@ page language="java" contentType="text/html; charset=utf-8"  
    2.     pageEncoding="utf-8"%>  
    3. <!DOCTYPE html>  
    4. <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>  
    5. <html lang="zh-cn">  
    6. <head>  
    7. <meta charset="utf-8">  
    8. <meta http-equiv="X-UA-Compatible" content="IE=edge">  
    9. <meta name="viewport" content="width=device-width, initial-scale=1.0">  
    10. <meta name="description" content="">  
    11. <meta name="author" content="">  
    12.   
    13. <title>用户登录</title>  
    14. </head>  
    15. <!-- CSS件 -->  
    16. <link rel="stylesheet" href="/css/bootstrap.min.css">  
    17. <link rel="stylesheet" href="/css/login.css">  
    18. <body>  
    19.     <div class="container">  
    20.         <form class="form-signin">  
    21.             <h2 class="form-signin-heading">Please sign in</h2>  
    22.             <input type="text" class="form-control" placeholder="Email address" required autofocus>   
    23.             <input type="password" class="form-control" placeholder="Password" required>   
    24.             <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>  
    25.         </form>  
    26.     </div>  
    27.   
    28.     <script src="http://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>  
    29.     <script src="/js/bootstrap.min.js"></script>  
    30. </body>  
    31. </html>  

    3.目录结构详见附件 

    项目地址https://github.com/leelance/spring-boot-all



    技术分享,关注茶爸爸微信公众号

  • 相关阅读:
    FATAL ERROR: please install the following Perl modules before executing /usr/bin/mysql_install_db:
    redis分布式锁原理与实现
    java中如何将 string 转化成 long
    FastJson中JSONObject用法及常用方法总结
    Spring IOC 一——容器装配Bean的简单使用
    静态代理和动态代理
    Spring AOP——Spring 中面向切面编程
    什么是分布式锁?实现分布式锁的三种方式
    @Consumes @Produces的作用
    pro、pre、test、dev环境
  • 原文地址:https://www.cnblogs.com/duyinqiang/p/5696522.html
Copyright © 2011-2022 走看看