thymeleaf

How to do validation in Spring MVC when there's a DTO?

怎甘沉沦 提交于 2020-12-15 05:10:01
问题 I have a person class and a personList DTO. The DTO is used to bind a list of persons object to the view. The user can edit one or more persons and click save to save the edits of all of them at once. Now I want to validate the new input. The problem is that the controller code "bindingResults.hasErrors()" is not returning the user input errors. I think it's because there's the personList DTO in the middle. Seems it is checking just errors in the personList class, but not in the person class

【SpringBoot】国际化

痴心易碎 提交于 2020-12-13 12:41:17
SpringBoot 国际化 SpringBoot进行国际化 properties中文乱码 SpringBoot 国际化的自动配置 AcceptHeaderLocaleResolver 自定义LocaleResolver 原理 SpringBoot进行国际化 编写国际化配置文件,抽取页面需要显示的国际化消息 在全局配置文件中写我们配置的位置 原理就是 SpringBoot自动配置好了管理国际化资源文件的组件 MessageSourceAutoConfiguration会去全局配置文件中找spring.messages开头的 找到对应的国际化配置文件 其中etBasename()的默认返回值是messages,也就是我们的国际化资源文件的名字可以直接写成messages,这样就不用再在全局配置文件中配置我们自己写的名字了 去页面获取国际化的值 SpringBoot用的模板引擎是Thymeleaf, 通过#{}来获取国际化资源的值 properties中文乱码 properties中写中文后 会有乱码问题我们可以在Idea设置 SpringBoot 国际化的自动配置 在SpringBoot中的WebMvcAutoConfiguration类中的localeResolver方法就是关于国际化的自动配置 LocalResolver用来获取区域信息对象 localeResolver()方法:

Thymeleaf + Spring MVC - Thymeleaf template parsing error on using checkbox input

主宰稳场 提交于 2020-12-13 11:31:41
问题 I'm following this tutorial which uses Spring MVC, Spring Boot and Thymeleaf as the view. I'm getting a Template Parsing Error when I use a checkbox input on the HTML form, and strangely, when I remove the checkbox input, everything works well. Here is the HTML - <!DOCTYPE html> <html lang="en" xmlns:th="https://www.thymeleaf.org/"> <head> <meta charset="UTF-8"> <title>Home Page</title> <style> h1,h2 { color: rebeccapurple; } </style> </head> <body> <h1>This is home page</h1> <h2>Enter data

Thymeleaf + Spring MVC - Thymeleaf template parsing error on using checkbox input

情到浓时终转凉″ 提交于 2020-12-13 11:31:32
问题 I'm following this tutorial which uses Spring MVC, Spring Boot and Thymeleaf as the view. I'm getting a Template Parsing Error when I use a checkbox input on the HTML form, and strangely, when I remove the checkbox input, everything works well. Here is the HTML - <!DOCTYPE html> <html lang="en" xmlns:th="https://www.thymeleaf.org/"> <head> <meta charset="UTF-8"> <title>Home Page</title> <style> h1,h2 { color: rebeccapurple; } </style> </head> <body> <h1>This is home page</h1> <h2>Enter data

Why “href” and “th:href” exist at the same time?

微笑、不失礼 提交于 2020-12-13 03:09:51
问题 I am reading a page using Thymeleaf. In "Edit page", there is a "Back" button for going back to "User List Page". The strange thing for me is this button has "href" and "th:href" at the same time. image detail of the button <!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"/> <title>user</title> <link rel="stylesheet" th:href="@{/css/bootstrap.css}"></link> </head> <body class="container"> <br/> <h1>修改用户</h1> <br/><br/> <div class="with:80%">

thymeleaf 之 th:each

非 Y 不嫁゛ 提交于 2020-12-09 16:50:17
<span th:each="cartInfo,stat:${checkedCartList}"> <input name="orderDetailList[0].skuId'" type="hidden" value="" /> <input name="orderDetailList[0].skuNum'" type="hidden" value="" /> <input name="orderDetailList[0].orderPrice'" type="hidden" value="" /> </span> 想要在html的循环中获取角标,引入thymeleaf 之 th:each状态变量,即stat index:当前迭代对象的index(从0开始计算) count: 当前迭代对象的index(从1开始计算) size:被迭代对象的大小 current:当前迭代变量 even/odd:布尔值,当前循环是否是偶数/奇数(从0开始计算) first:布尔值,当前循环是否是第一个 last:布尔值,当前循环是否是最后一个 例如: <th th:text="${Stat.index}">状态变量:index</th> <th th:text="${Stat.count}">状态变量:count</th> <th th:text="${Stat.size}">状态变量:size<

Inject html into thymeleaf template

荒凉一梦 提交于 2020-12-09 04:10:39
问题 I have thymeleaf templates lying in database, First I retrieve template and process it: String processedTemplate = templateEngine.process(databaseTemplate, context); So now processedTemplate contains html as a String . Then I retrieve another template and do basicly the same, but I want also inject previous template into it, so the java code should look like: Context context = new Context(Locale.ENGLISH); context.setVariable("htmlToInject", processedTemplated); String result = templateEngine

Inject html into thymeleaf template

感情迁移 提交于 2020-12-09 04:08:09
问题 I have thymeleaf templates lying in database, First I retrieve template and process it: String processedTemplate = templateEngine.process(databaseTemplate, context); So now processedTemplate contains html as a String . Then I retrieve another template and do basicly the same, but I want also inject previous template into it, so the java code should look like: Context context = new Context(Locale.ENGLISH); context.setVariable("htmlToInject", processedTemplated); String result = templateEngine

Thymeleaf Modify and Post Current Object

為{幸葍}努か 提交于 2020-12-08 06:09:22
问题 I have a form and post data into controller via Thymeleaf: <form action="lia.html" th:action="@{/lia}" th:object="${myRequest}" method="post"> At another place of my html page, if a user click a particular button, I want to modify that object and send it to same controller. I have already that object which has been initialised. Button is not a part of any form. How can I send that object into a controller with Thymeleaf. PS: I know that I can send it via Javascript or put such buttons into a

Thymeleaf Modify and Post Current Object

不问归期 提交于 2020-12-08 06:06:03
问题 I have a form and post data into controller via Thymeleaf: <form action="lia.html" th:action="@{/lia}" th:object="${myRequest}" method="post"> At another place of my html page, if a user click a particular button, I want to modify that object and send it to same controller. I have already that object which has been initialised. Button is not a part of any form. How can I send that object into a controller with Thymeleaf. PS: I know that I can send it via Javascript or put such buttons into a