欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

springboot中的html引入js、css文件

程序员文章站 2022-07-10 17:43:25
...

在Spring Boot项目中,默认配置的/**映射到/static,一般src/main/resources/static目录用于存放各类静态资源文件,例如css、js和image等。src/main/resources/templates用于存放页面文件,例如html,jsp等。

目录结构如下:
springboot中的html引入js、css文件
application.yml配置如下:

server:
  port: 8080
spring:
  thymeleaf:
    #这个是配置html资源目录,如果直接放在templates下不用配置
    #prefix: classpath:/templates/view/
    cache: false

html中引入js、css:

<link rel="stylesheet" type="text/css" href="css/normalize.css" />
<link rel="stylesheet" type="text/css" href="css/default.css">
<script src='js/prefixfree.min.js'></script>
<link rel="stylesheet" type="text/css" href="css/styles.css">

controller代码如下:

@Controller
public class LoginController {

    @RequestMapping("login")
    public String login(){
        return "index";
    }
}