我的项目结构 image url
和我的dev.yml:
server:
port: 9999
servlet:
context-path: /app
spring:
datasource:
url: jdbc:mysql://localhost:3306/app?serverTimezone=GMT%2B8&characterEncoding=utf-8
username: root
password: password
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
database: mysql
hibernate:
ddl-auto: update
show-sql: true
thymeleaf:
encoding: utf-8
cache: false
mode: HTML
prefix: classpath:/templates/
resources:
static-locations: classpath:/static/
我的演示控制器:
package com.personal.app.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class Index {
@GetMapping("/index")
public String toIndex(Model model) {
return "index";
}
}
我的index.html:
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<!-- Fontawesome -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css">
<link rel="stylesheet" type="text/css" href="css/styles.css">
<script src="js/jquery-3.3.1.slim.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<title>Home</title>
</head>
<body>
<p>test content</p>
</body>
</html>
当我开始春季项目时。 Chrome控制台显示css和js文件的404找不到错误
我的静态位置配置有问题吗?
我尝试在CSS /和js /之前添加/ app,但不起作用
有解决方案吗?预先感谢。
答案 0 :(得分:-1)
尝试一下:
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="resources/css/bootstrap.min.css">
<!-- Fontawesome -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css">
<link rel="stylesheet" type="text/css" href="css/styles.css">
<script src="resources/js/jquery-3.3.1.slim.min.js"></script>
<script src="resources/js/popper.min.js"></script>
<script src="resources/js/bootstrap.min.js"></script>
<title>Home</title>
</head>
<body>
<p>test content</p>
</body>
</html>