第一步:准备静态资源
- 在resources/static/imgs下放置一张名称为mm01.jpg的图片
- 在resources/static/css下创建文件demo.css
.cc{
font-size: 38px;
color: red;
}
- 在resources/static/js下创建文件demo.js
function fun() {
alert(3+2);
}
第二步:修改index.html
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>首页</title>
<link type="text/css" th:href="@{/css/demo.css}" rel="stylesheet"/>
</head>
<body>
<h2>首页</h2>
<img th:src="@{/imgs/mm01.jpg}" alt="">
<script th:src="@{/js/demo.js}"></script>
<script>
fun()
</script>
</body>
</html>
第三步:修改SpringSecurity配置文件
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/openIndex").permitAll()
.antMatchers("/**/*.css","/**/*.js","/imgs/**").permitAll()
.anyRequest().authenticated()
.and()
.csrf().disable();
}