Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 控制器头中的requestMapping注释,;并且不会找到thymeleaf静态内容_Spring_Spring Mvc_Spring Boot_Thymeleaf - Fatal编程技术网

Spring 控制器头中的requestMapping注释,;并且不会找到thymeleaf静态内容

Spring 控制器头中的requestMapping注释,;并且不会找到thymeleaf静态内容,spring,spring-mvc,spring-boot,thymeleaf,Spring,Spring Mvc,Spring Boot,Thymeleaf,当我在控制器中添加requestmapping时,将找不到thymeleaf静态内容,例如 @Controller @RequestMapping(value = "/section") public class SectionController { @Autowired private SectionService sectionService; @RequestMapping(value = "/list") public String listSection(Model model)

当我在控制器中添加requestmapping时,将找不到thymeleaf静态内容,例如

@Controller
@RequestMapping(value = "/section")
public class SectionController {

@Autowired
private SectionService sectionService;

@RequestMapping(value = "/list")
public String listSection(Model model){
    model.addAttribute("result",sectionService.listSection());
    return "views/listSection";
}

@RequestMapping(value = "/save", method = RequestMethod.POST)
public String saveSection(Section section){
    sectionService.saveSection(section);
    return "redirect:/section/list";
}}
listSection.html
使用thymeleaf

  <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script th:src="@{jquery/jquery-3.2.1.js}" ></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script th:src="@{bootstrap/3.3.7v/js/bootstrap.js}"></script>

<!-- Bootstrap -->
<link th:href="@{bootstrap/3.3.7v/css/bootstrap.css}" rel="stylesheet">

并启动服务,如将报告错误,静态内容将找不到


我移除了控制器类head中的requestMapping,并访问
http://localhost:9090/list
一切正常,请告诉我原因

问题是您正在获取具有相对URL的静态内容。不是从绝对根路径(
/
)开始的。因此,对于相对url,它将请求当前url的相对根路径(例如对于
/section/list
,它将请求您的内容的
/section/
+
路径),因为
/section
是此url的根路径。但是当你尝试像
/节
/列表
这样的URL时,它正在请求你的内容的
/
+
路径中的内容,因为
/
是这个URL的根路径

如果链接URL是正确的,那么如果您从根目录创建URL,它应该可以工作。更改
listSection.html
,如下所示

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script th:src="@{/jquery/jquery-3.2.1.js}" ></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script th:src="@{/bootstrap/3.3.7v/js/bootstrap.js}"></script>

<!-- Bootstrap -->
<link th:href="@{/bootstrap/3.3.7v/css/bootstrap.css}" rel="stylesheet">

问题是您正在获取具有相对URL的静态内容。不是从绝对根路径(
/
)开始的。因此,对于相对url,它将请求当前url的相对根路径(例如对于
/section/list
,它将请求您的内容的
/section/
+
路径),因为
/section
是此url的根路径。但是当你尝试像
/节
/列表
这样的URL时,它正在请求你的内容的
/
+
路径中的内容,因为
/
是这个URL的根路径

如果链接URL是正确的,那么如果您从根目录创建URL,它应该可以工作。更改
listSection.html
,如下所示

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script th:src="@{/jquery/jquery-3.2.1.js}" ></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script th:src="@{/bootstrap/3.3.7v/js/bootstrap.js}"></script>

<!-- Bootstrap -->
<link th:href="@{/bootstrap/3.3.7v/css/bootstrap.css}" rel="stylesheet">