嗨,我是SpringBoot的新手,我正在开发一个编辑产品的功能,在我的类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
从view panel.html加载的标题和标题:
表单编辑.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">
暂无答案!
目前还没有任何答案,快来回答吧!