一个低级错误…
今天将前台那边写好的index放在项目中
发现run后访问不到样式,只有thymeleaf引擎的html静态资源
找到以下解决方案:
-
没有设置静态资源访问路径
-
写个配置类
import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** * @program: neo4j * @description: 配置类 * @author: YxYL * @create: 2022-06-05 14:28 **/ @Configuration public class MyConfig implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); } }
-
在核心配置文件中设置路径
spring: thymeleaf: prefix: classpath:/templates suffix: .html cache: false resources: static-locations: classpath:/resources/ classpath: /templates/static/
-
-
设置了扫描路径,可能在html中link标签的属性没有添加
rel="stylesheet"
<link rel="stylesheet" href="/css/index.css">
-
没事就清清memory咯~~~
如果单纯是访问不到html资源(400),可能需要在pom.xml
文件中配置映射文件路径
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>