栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

无法在Spring Boot中加载CSS

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

无法在Spring Boot中加载CSS

你需要放入CSS

/resources/static/css
。此更改为我解决了问题。这是我当前的目录结构。

src  main    java      controller        WebAppMain.java    resources      views        index.html      static        css          index.css          bootstrap.min.css

这是我的模板解析器:

public class WebAppMain {  public static void main(String[] args) {    SpringApplication app = new SpringApplication(WebAppMain.class);    System.out.print("Starting app with System Args: [" );    for (String s : args) {      System.out.print(s + " ");    }    System.out.println("]");    app.run(args);  }  @Bean  public ViewResolver viewResolver() {    ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();    templateResolver.setTemplateMode("XHTML");    templateResolver.setPrefix("views/");    templateResolver.setSuffix(".html");    SpringTemplateEngine engine = new SpringTemplateEngine();    engine.setTemplateResolver(templateResolver);    ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();    viewResolver.setTemplateEngine(engine);    return viewResolver;  }}

以防万一,这是我的index.html:

<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring3-3.dtd"><html lang="en" xmlns="http://www.w3.org/1999/xhtml"      xmlns:th="http://www.thymeleaf.org"><head>    <title>Subscribe</title>    <meta charset="utf-8" />    <meta http-equiv="X-UA-Compatible" content="IE=edge" />    <meta name="viewport" content="width=device-width, initial-scale=1" />        <!-- Bootstrap -->    <link type="text/css" href="css/bootstrap.min.css" rel="stylesheet" />    <link type="text/css" href="css/index.css" rel="stylesheet" /></head><body><h1> Hello</h1><p> Hello World!</p>    <!-- jQuery (necessary for Bootstrap's Javascript plugins) -->    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>    <!-- Include all compiled plugins (below), or include individual files as needed -->    <script src="js/bootstrap.min.js"></script></body></html>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/420525.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号