thymeleaf 相关问题

Thymeleaf是一个XML / XHTML / HTML5模板引擎(可扩展到其他格式),可以在Web和非Web环境中工作。它更适合在Web应用程序的视图层提供XHTML / HTML5,它甚至可以在脱机环境中处理任何XML文件。它提供了一个可选模块,用于与Spring MVC集成,因此您可以在使用此技术的应用程序中将其用作JSP的完全替代,即使使用HTML5也是如此。

Cookie SameSite 属性

在使用 thymeleaf 的 spring boot 应用程序中。 当用户在选择中选择项目时,我在 cookie 中设置一个值以便能够返回 ... 在使用 thymeleaf 的 spring boot 应用程序中。 当用户在选择中选择项目时,我在 cookie 中设置一个值以便能够返回 <div class="col-sm-3"> <form> <div class="form-group"> <label for="testType" th:text="#{testTypeEnum.select.label}"></label> <select class="form-control" id="testType" > <option th:value="NULL" selected="selected" th:text="#{form.select.empty}"></option> <option th:each="testType : ${testTypes}" th:value="${testType}" th:text="#{'testTypeEnum.'+${testType}}"></option> </select> </div> </form> </div> <script type="text/javascript" th:inline="javascript"> $(document).ready(function () { $("#testType").on('change', function() { var valueSelected= this.value; document.cookie = "selectedTestType="+valueSelected; var url = "/samplestesttable?testTypeValue="+valueSelected; $("#testListResultFragment").load(url); }); function getCookie(cname) { var name = cname + "="; var decodedCookie = decodeURIComponent(document.cookie); var ca = decodedCookie.split(';'); for(var i = 0; i <ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } var selectedTestType = getCookie("selectedTestType"); if(selectedTestType !== ""){ $("#testType").val(selectedTestType).change(); } }); </script> 效果很好。 但是几个月后,我在浏览器开发控制台中看到了 Cookie“selectedTestType”没有正确的“SameSite”属性值 也许现在有更好的方法来做同样的事情?

回答 0 投票 0

多模块 spring boot 项目中 tymeleaf 的图像和静态文件必须存储在哪里?

我有一个多模块 spring boot 项目。其中一个模块是网络,它包括 thymeleaf。我将图像 css 和 javascript 等资产存储在 resources/static/ 下并导入图像文件...

回答 0 投票 0

Spring Security Login 无法正常工作并返回根 URL

在我的应用程序中,当成功登录时,我有登录表单来访问“uproject.hmtl”。但是由于错误,它返回到登录页面。当我检查我提供的用户详细信息时

回答 0 投票 0

thymeleaf 中的嵌套对象返回 null

这是我更新员工实体的表格。 这是我更新员工实体的表格。 <input name="_method" type="hidden" value="put" /> <input type="text" style="background-color:#EEEEEE" th:field="*{id}" hidden readonly placeholder="Enter mail" class="form-control col-4 mb-4" /> <label>Member Email</label> <input type="text" style="background-color:#EEEEEE" th:field="*{email}" placeholder="Enter mail" class="form-control col-4 mb-4" /> <label>Availability for Runner</label> <select class="form-control col-4 mb-4" style="background-color:#EEEEEE;" th:field="*{isAvailable}" name="type"> <option th:value="1" >Available</option> <option th:value="0" >Not Available</option> </select> <label>Current Desk</label> <select th:field="*{currentDropOffPoint}" class="form-control col-4 mb-4" style="background-color:#EEEEEE" name="type"> <option th:each="point : ${dropOffPoints}" th:value="${point}" th:text="${point}"></option> </select> <label>Member Role</label> <select th:field="*{role.name}" class="form-control col-4 mb-4" style="background-color:#EEEEEE"name="type"> <option th:each="role : ${roles}" th:value="${role}" th:text="${role}"></option> </select> <div style="width: 790px;height: 100px;background-color: #F6F6F6;border-radius: 20px"> <button th:href="@{/api/v1/portal/showList}" class="btn btn-primary col-2" style="color: red;background-color: #00000014;border-color: #00000014;margin: 26px 26px 26px 21px;width: 82px;height: 48px;border-radius: 999px" type="submit">Delete</button> <button class="btn btn-primary col-2" type="submit" style="background-color: #000000; border-color: #000000;float: right;width: 70px;height: 48px;margin: 26px 21px 26px 10px;border-radius: 999px">Save</button> <button th:href="@{/api/v1/portal/staff/showList}" class="btn btn-primary col-2" style="color: black;background-color: #00000014;border-color: #00000014;float: right;width: 85px;height: 48px;margin-top: 26px;margin-bottom: 26px;margin-right: 10px;border-radius: 999px " type="submit">Cancel</button> </div> </form> 这是员工实体。 data class StaffDTO( val id: StaffId, val email: String, val role: RoleDTO?, val isAvailable: Boolean?, val currentDropOffPoint: Long? ) fun Staff.toDto() = StaffDTO(id, email, role?.toDto(), isAvailable, currentDropOffPoint) 这是roleDTO data class RoleDTO( val id: RoleId=1L, val name: String="OPERATOR" ) fun Role.toDto() = RoleDTO(id, name) 这是控制器 @Controller class UpdateController( private val staffServiceImpl: StaffServiceImpl ) { @GetMapping("/portal/updateStaff/{id}") fun showStaffUpdateForm(@PathVariable("id") staffID: StaffId): ModelAndView? { val mav = ModelAndView("update-admin-form") val roles = listOf("OPERATOR","RUNNER","EXECUTOR","ADMIN") val dropOffPoints = listOf(1L,2L,3L,4L,5L) val staff = staffServiceImpl.findById(staffID)!!.toDto() val isAvailableObject = true; val isAvailable= listOf(true,false) mav.addObject("dropOffPoints",dropOffPoints) mav.addObject("staff", staff) mav.addObject("roles",roles) mav.addObject("boolean",isAvailableObject) mav.addObject("isAvailable",isAvailable) return mav } @RequestMapping("/portal/saveStaff/{id}") fun updateStaff(@PathVariable("id") id: Long?, @ModelAttribute staffDTO: StaffDTO): RedirectView? { if (staffDTO != null) { staffServiceImpl.updateStaff(staffDTO) } val redirectView = RedirectView() redirectView.url = "http://localhost:8080/portal/test" return redirectView } 问题是,即使我设置了 role 的属性,它也会作为 null 返回给控制器,并抛出 NoSuchMethodException 。我在互联网上搜索了这个异常,它说这个异常被抛出是因为 roleDTO 没有 args 构造函数。但是当我为 roleDTO 提供默认值时,它仍然会抛出相同的异常。 对此有什么解决方案吗? 问题出在 StaffDTO 的构造函数上。 当我在 staffDTO 中创建一个 RoleDTO 作为默认值时,问题就解决了。 在使用 thymeleaf 时,您还需要创建子对象。您不能将 null 作为默认值发送给子对象。

回答 1 投票 0

处理 Spring Boot 和 Thymeleaf 中未定义的问题列表

我有一个网页,其中包含未定义的带有复选框的列表。 在控制器端,我想获取已选择的字符串数组。 使用 Spring Bo 执行此操作的最佳方法是什么...

回答 0 投票 0

Thymeleaf {'data:image/jpeg;base64'} 用于显示数据库图像的语法不起作用

所以,我在 Springboot 编程和 rn 方面仍然是新手,我得到了一个任务,我需要将上传的图像存储到我的 phpmyadmin 数据库中,并使用 Thymeleaf 将其显示在 html 上以创建目录。所以...

回答 0 投票 0

在春靴百里香中使用枚举

我是初学者后端开发人员。我正在构建一个应用程序,使用 Spring、Hibernate,当然还有 Thymeleaf 来获取视图。我遇到了这样的问题。我想将数据从 edit.html 发送到另一个 c ...

回答 0 投票 0

为什么找不到 Thymeleaf 模板?

我有一个 Spring Boot 2.1.6 应用程序(Spring 5),我想使用 Thymeleaf 作为我的模板引擎。我按照在线教程来设置我的项目、视图和控制器,当我...

回答 5 投票 0

DefaultSuccessUrl 登录后无法正常打开

登录后无法获取defaultsuccessurl。而且我还在浏览器中看到了 whiatable 错误页面。但是当我使用后退按钮时,我得到了 defaultsuccessurl。我已经检查了那里的当局...

回答 0 投票 0

我正在尝试使用 thymleef 和 springboot 打印到屏幕

这是我试图在 html 上显示的内容 ... 这就是我试图在 html 上显示的内容 <div class="review"> <div class="row"> <!--end col-md-3--> <div class="col-md-9"> <div class="comment"> <div class="comment-title"> <h4> <td th:text="${username}"></td> </h4> </div> <dl class="visitor-rating"> <dt>user ID</dt> <dd><td th:text="${userid}"></td></dd> <dt>user Tel.</dt> <dd><td th:text="${tel}"></dd> <dt>user email</dt> <dd><td th:text="${email}"></dd> </dl> </div> </div> </div> </div> 这就是尝试从控制器发送数据的方式 String username = memDto.getUsername(); String email = memDto.getEmail(); String tel = memDto.getTel1(); String userid = memDto.getUserid(); mav.addObject("username", username); mav.addObject("email", email); mav.addObject("tel", tel); mav.addObject("userid", userid); 我在数据库中有数据,但我不知道为什么数据不显示

回答 0 投票 0

How to implement a Directory chooser in spring-boot using thymeleaf

我有一个返回 Thymeleaf 表单的 Spring Boot 应用程序。 我想添加一个按钮,让用户选择一个目录并将目录路径作为字符串(或文件)获取。我不在乎

回答 1 投票 0

在“org”类型的对象上找不到字段或属性 - Thymeleaf-Spring

我已经尝试了所有可能的方法,但我自己不喜欢我得到的解决方案。 我正在使用 Spring 框架和 Thymeleaf。在我的实体类中,我将我的属性声明为私有的,如下所示 公众...

回答 4 投票 0

是否可以使用 th:attrappend 与 JSON 类型格式?

让我有一个基本的 html 类(片段),其中包含基本的 x-bind:class 属性,内容如下: 让我有一个基本的 html 类(片段),其中包含具有以下内容的基本 x-bind:class 属性: <th:block th:fragment="appButton(text)" th:with=" attrappends=${attrappends} ?: 'data-thyme=attraappend', attributes=${attributes} ?: 'data-thym=default' " > <button th:attrappend="__${attrappends}__" th:attr="__${attributes}__" th:text="${text}" x-bind:class="{ 'loading': $store.loadingOrDisabledState.stateVal, } " , ></button> </th:block> 现在当我在 html 文件中调用这个片段时(假设我想更新这个 html 中的 x-bind:class) <button th:replace="~{fragments/app-button :: appButton( text='...', attrappends=' |x-bind:class|=|{'anotherCssValue' :withAnotherCondition}|, ', attributes='... ', )}" ></button> 我的期望是将所有条件组合在一个对象中: { 'loading': $store.loadingOrDisabledState.stateVal, 'anotherCssValue' :withAnotherCondition } 但是 thymeleaf 产生以下值(无效): { 'loading': $store.loadingOrDisabledState.stateVal, } { 'anotherCssValue' :withAnotherCondition } ?

回答 0 投票 0

在Spring boot和spring security中登录后无法访问页面

我有一个实现 spring 安全的 spring boot 应用程序。在应用程序中,有一个导航栏和在 thymeleaf 中应用的片段。登录后,我无法使用导航栏访问给定的 url。我无法...

回答 0 投票 0

为什么我无法在我的添加员工表单中显示自定义错误消息 (hibernate-Spring-boot-thymeleaf)

`当将 Spring Boot 与 Thymeleaf 一起使用时,数据验证将应用于代码,但尽管验证成功,数据仍未保存到数据库中。此外,错误消息不是...

回答 0 投票 0

Spring Boot Spring Security CSRF 403 错误

我在项目中使用Spring Security的时候 我的购物车出现 403 错误 CartController 的 logger.info("NUMBER"+cart_id) 没有执行 可能是 CSRF 问题 购物车.html 当我在项目中使用Spring Security时 我的购物车出现 403 错误 CartController 的 logger.info("NUMBER"+cart_id) 没有执行 可能是 CSRF 问题 Cart.html <form method="post" action="orderAdd"> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/> <table class="alt"> <thead> <tr> ... </tr> </thead> <tbody> <tr th:each="Cart:${cartVO}"> <td style="vertical-align: middle;" width="120"> <input type="checkbox" th:value="${Cart.cart_id}" name="valCartId" id="cid" style="opacity:1;appearance:checkbox;margin-right:0"/> <strong th:text="${Cart.name}" ></strong> </td> <td style="width: 123px; height: 124px;"><a href="" class="image"><img th:src="@{${Cart.image}}" alt="productIMG" height="100" /></a></td> <td th:text="${Cart.spec}" style="vertical-align: middle;" width="70"></td> <td th:text="${Cart.price}" style="vertical-align: middle;" width="50"></td> <td th:text="${Cart.cart_Quantity}" style="vertical-align: middle;" width="70"></td> </tr> </tbody> </table> <div class="col-12"> <ul class="actions"> <li><input type="submit" value="BUY" class="primary" /></li> <li><input type="submit" value="DELETE" formaction="/cartDelete"/></li> </ul> </div> </form> 购物车控制器<--- It seems that this method is not call, because logger.info("NUMBER"+cart_id) is not executed @Controller public class CartController { @PostMapping("/cartDelete") public String delete(@RequestParam("valCartId") List<Long> cart_id) { logger.info("NUMBER"+cart_id); cartService.delete(cart_id); return "redirect:/cart"; } } 试试这个:- @控制器 公共类 CartController { @DeleteMapping("/cartDelete/{cart_id}") public String delete(@PathVariable Long cart_id) { logger.info("NUMBER"+cart_id); cartService.delete(cart_id); return "redirect:/cart"; } } 我犯了一个愚蠢的错误 我没有正确编码 Thymeleaf <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/> 改为 <input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>

回答 2 投票 0

springMVC 未能实例化 ThymeleafView

这是一个在tomcat上使用Thymeleaf,idea,maven的springMVC程序,tomcat可以正常运行,程序可以进入一个Controller,但是一旦Controller返回一个,tomcat就会返回一个500的web...

回答 1 投票 0

Thymeleaf th:每次循环渲染一个图表js条形图

这是我最后一次尝试。我已经遇到这个问题好几个星期了,但没有运气。我有一个带有 thymeleaf 的 spring crud 应用程序,用于圆盘高尔夫应用程序。您可以添加课程,然后为登录的人添加轮次...

回答 0 投票 0

Thymeleaf - 压平表单字段

我正在尝试创建一个 PDF 并使一些复选框不可编辑,否则它们可以更改,这不是我需要的。 我尝试使用 我正在尝试创建一个 PDF 并使一些复选框不可编辑,否则它们可以更改,这不是我需要的。 我尝试使用 <input type="checkbox" id="randomId" th:checked="true" readonly="readonly"/>,但它不工作,试图禁用它,但仍然不工作。有什么建议吗? 要使复选框不可编辑,可以使用 disabled 属性而不是 readonly。 disabled 属性阻止用户与元素完全交互,而 readonly 允许用户查看复选框的当前值,但他们不能更改它。 因此,您的代码应如下所示: <input type="checkbox" id="randomId" checked="checked" disabled="disabled"/> 这将创建一个复选框,该复选框最初被选中并且不能被用户更改。 用disabled代替readonly。 readonly 仅影响字段的可编辑文本值 - 而复选框具有 state 不是可编辑值。 您实际上不需要任何特定的 Thymeleaf 变量。您可以在 Thymeleaf 模板中使用以下纯 HTML: <input type="checkbox" id="randomId" disabled checked> 如果你确实想使用 Thymeleaf 表达式,你可以使用这个: <input type="checkbox" id="randomId" th:disabled="${true}" th:checked="${true}"> 这些是 Thymeleaf 布尔属性. 我只会使用纯 HTML。

回答 2 投票 0

如何使用 javax mail with thymeleaf

我已经搜索了很多,但没有找到任何答案,即使用 thymeleaf 模板和 javax.mail 每个示例都使用 spring-boot-starter-mail 你们有解决方案吗? 这是...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.