Spring Boot+Thymeleaf:无法解析 Spring EL 表达式 [英] Spring Boot+Thymeleaf: th not able to resolve a Spring EL expression
问题描述
我正在使用 spring boot+thymeleaf+neo4j.一切正常,除了 thymeleaf 无法解析模板 product_grid.html 中 th:each 块中使用的product"变量的一些属性,其中包括 th:src="${product.URL}", th:text="${Product.title}" 和 th:action="@{/product/(${Product.getId()})}" 表达式在表单标签中.th:text="${Product.Price}" 正在工作.当我检查浏览器中生成的代码时,src 标签为空(src:""),包含标题标签的文本属性未显示在浏览器中.th:action 工作正常,但是当我单击表单内定义的按钮时,url 更改为 http://localhost:8080/product/?btn=View+Product而不是浏览器控制台中显示的以下代码http://localhost:8080/product/?1
注意:我试图从存储在 neo4j 数据库中的字段中获取图像 url.项目目录为:项目目录图片
模板:product_grid.html
<html xmlns:th="http://www.thymeleaf.org" ><头><meta charset="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"><title>产品</title><meta name="viewport" content="width=device-width, initial-scale=1"><script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.bundle.min.js"integrity="sha384-feJI7QwhOS+hwpX2zkaeJQjeiwlhOP+SdQDqhgvvo1DsjtiSQByFdThsxD"crossorigin="匿名"></script><script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjPVCUar5"7s/脚本><link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcFAWJSAGiX"crossorigin="匿名">头部><身体><nav class="navbar navbar-expand-lg navbar-dark bg-dark"><a class="navbar-brand" href="#">Grada</a><button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"aria-expanded="false" aria-label="切换导航"><span class="navbar-toggler-icon"></span>按钮><div class="collapse navbar-collapse" id="navbarSupportedContent"><ul class="navbar-nav mr-auto"><li class="nav-item "><a class="nav-link" href="#">首页<span class="sr-only">(当前)</span></a><li class="nav-item"><a class="nav-link">我最好的产品</a><li class="nav-item"><a class="nav-link" th:href="@{/login}">登录</a><form class="form-inline my-2 my-lg-0"><input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search"><a class="btn btn-outline-success my-2 my-sm-0" href="file:///home/madhav/SPM/Grada/public_html/product.html">搜索</a></表单>
</nav><div class="container text-center"><div class="row"><div th:each="Product:${products}" class="col-lg-3 col-sm-12 col-md-6 my-2 p-auto"><div class="card"><div class="card-body"><img src="http://via.placeholder.com/150x150/888/111" th:src="${Product.URL}" alt="img" class="card-img-top img-thumbnailimg-流体"><div class="card-title Lead" th:text="${Product.title}">一些产品名称</div><div class="card-text">价格:₹<span th:text="${Product.Price}">400</span></div>
<form method="GET" action="/" th:action="@{/product/(${Product.getId()})}"><input type="submit" name="btn" class="form-control btn btn-primary" value="查看产品"><input type="submit" name="btn" class="form-control btn btn-primary" value="加入购物车"></表单>