SpringBoot+Thymeleaf问题

 

springboot在controller返回数据到thymeleaf报404

用springboot做一个例子,访问controller可以返回数据,但是到thymeleaf却报404,

检查发现路径等没有问题,查阅资料得知

这是因为maven仓库jar包问题,把maven仓库中的所有jar包都删除了,然后重新下载,再启动项目

或者在pom文件的

properties

标签下加入

 <thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
 <thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>

  

Thymeleaf页面的jquery无效

在<head>标签中写的jquery无效

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:include="fragment::header">
    <meta charset="UTF-8">
    <title></title>
    <script>
        ......   // 此处会被覆盖
    </script>
</head>

  

原因:使用  <head th:include="fragment::header">  集中引入外部资源时,会覆盖原页面中的<head>标签,则<script>标签中的代码在页面源码会不存在

引入后的页面源码<head>:

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link href="/css/style.css" rel="stylesheet"/>
    <link href="/bootstrap/css/bootstrap.css" rel="stylesheet"/>
    <script src="/js/jquery-3.0.0.min.js" type="text/javascript"></script>
    <script src="/bootstrap/js/bootstrap.js" type="text/javascript"></script>
    <title>fragment</title>
</head>

 

  

 

posted @ 2019-03-21 09:49  无拘  阅读(882)  评论(0)    收藏  举报
TOP