spring boot inport css 404

问题描述 投票:0回答:1

我的项目结构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,但不起作用

任何解决方案?在此先感谢。

java spring-boot
1个回答
0
投票

尝试一下:

<!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>
© www.soinside.com 2019 - 2024. All rights reserved.