zoukankan      html  css  js  c++  java
  • Spring Boot遇到的某些问题

    Spring Boot遇到的某些问题

    1.关于templates的html包格式问题:

    <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <java.version>1.8</java.version>
            <spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
            <!--以下两项需要如果不配置,解析themleaft 会有问题-->
            <thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
            <thymeleaf-layout-dialect.version>2.0.5</thymeleaf-layout-dialect.version>
        </properties>
    
    

    Tomcat配置Context 标签以后Tomcat启动不了

    因为项目要访问本地硬盘的文件所以要去Tomcat的server.xml里配置Context ,

    <Context path="/image" docBase="F:fileimage" debug="0" reloadable="true"></Context>

    结果弄了一个多小时发现是docBase的路径不存在。因为我们是上传文件才会建立文件夹,导致一直找不到问题出在哪,记录一下

    2.关于thymeleaf引入js.Css等:

    <head th:fragment="header">
    
      <meta charset="UTF-8" />
    
      <title th:text="#{head.title}"></title>
    
      <meta name="viewport" content="width=device-width, initial-scale=1" />
    
      <link rel="shortcut icon" th:href="@{/static/img/favicon.gif}" type="image/gif" />
    
      <link rel="stylesheet" th:href="@{/resources/css/bootstrap.min.css}" />
    
      <link rel="stylesheet" th:href="@{/resources/css/jquery.ui.all.css}" />
    
    <link rel="stylesheet" th:href="@{/resources/css/jquery.ui.customer.css}" />
    
      <script th:src="@{/resources/js/jquery-1.9.1.min.js}"></script>
    
      <script th:src="@{/resource/js/bootstrap.min.js}"></script>
    
    </head>
    
    

    下面在你要的页面 引入这个片段就行<head th:include="theme/fragments::header" /> 他就相当于jsp 中我们常用的<%@ include file="/WEB-INF/jsp/public/header.jspf"%>

    3.如果静态资源被拦截或者不生效,请尝试以下配置:

    增加配置类:

    package com.home.config;
    
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
    
    @Configuration
    public class MyWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {
        /**
         * 配置静态访问资源
         * @param registry
         */
        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
            super.addResourceHandlers(registry);
        }
    }
    
  • 相关阅读:
    【已解决】ERR_BLOCKED_BY_XSS_AUDITOR:Chrome 在此网页上检测到了异常代码:解决办法
    【已解决】Microsoft visual c++ 14.0 is required问题解决办法
    爬虫处理网站的bug---小于号未转化为实体符
    pymysql 在数据库中插入空值
    python 正则括号的使用及踩坑
    pymysql 解决 sql 注入问题
    python3 操作MYSQL实例及异常信息处理--用traceback模块
    LeetCode 837. 新21点 | Python
    LeetCode 面试题64. 求1+2+…+n | Python
    LeetCode 101. 对称二叉树 | Python
  • 原文地址:https://www.cnblogs.com/charlypage/p/9383411.html
Copyright © 2011-2022 走看看