你需要放入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>



