java - @PathVariable 不加载资源 [CSS & JS] - Thymeleaf
问题描述
嗨,我是 Spring Boot 的新手,我正在开发用于编辑产品的功能,在我的类 ProductController 中,我使用 @PathVariable 接收产品 ID,加载时 form-edit.html 不加载 css 和js 文件。我尝试配置 MVC 添加 ResourcesHandler 但不适用于此视图...
MVCConnfig.java
WebMvcConfigurer.super.addResourceHandlers(registry);
registry.addResourceHandler("/webjars/**").addResourceLocations("/webjars/");
registry
.addResourceHandler("/resources/**")
.addResourceLocations("/resources/");
产品控制器.java
@RequestMapping(value = "/form-edit/{id}")
public String editar(@PathVariable(value = "id") Integer id, Map<String, Object> model,
RedirectAttributes flash) {
Producto producto = null;
if (id > 0) {
producto = productoService.findOne(id);
if (producto == null) {
flash.addFlashAttribute("error", "El ID del producto no existe en la BBDD!");
return "redirect:/panel";
}
} else {
flash.addFlashAttribute("error", "El ID del producto no puede ser cero!");
return "redirect:/panel";
}
..Here load some lists for catalogs in select option..
return "panel-form";
}
应用程序属性
spring.web.resources.chain.strategy.content.enabled=true
spring.web.resources.chain.strategy.content.paths=/resources/**
spring.web.resources.chain.strategy.fixed.enabled=true
spring.web.resources.chain.strategy.fixed.version=v12
从视图 Panel.html 加载标题和头部:
表单-edit.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="panel :: head"></head>
<body>
<header th:replace="panel :: header"></header>
<div class="container py-4">
<div class="card bg-dark text-white">
<div class="card-header" th:text="${titulo}"></div
<form th:action="@{/form}" th:object="${producto}"
method="post"
enctype="multipart/form-data">
解决方案
推荐阅读
- javascript - 如何根据背景颜色轻松反转文本颜色
- python - 用Python将文件的内容插入另一个文件的中间?
- android - How to create a ListView that swipes to both left and right
- video - 容器中的 h.265/HEVC(mp4、mkv....)和 h.265/HEVC 附件 B 原始文件有什么不同?
- react-native - 在进行异步调用时,组件似乎没有在从同一个 thunk 调度的多个操作之间更新?
- java - The file show more than one when export into .pdf JAVA
- typescript - TypeScript AST 转换删除所有空行
- sql-server - 在单独的表中对聚合数据进行分组
- r - What's the meaning of ".." in R
- asynchronous - how does use_locking in optimizer influence performance