小编kry*_*urr的帖子

Thymeleaf 和 #fields.hasErrors

我正在为学校做这项作业。使用 SpringMVC、Hibernate JPA 和 Thymeleaf。下面的代码涉及一个名为“ stringGrade ”的特定属性。我想使用 Hibernate Validator 验证该字段中的输入。我似乎无法让 Thymeleaf 读懂这个表达式。在视图中循环的 arrayList 的名称属性为“deliverables[0].stringGrade”,依此类推,具体取决于有多少个。我尝试使用“ Deliverables[ ${stat.index} ].name ”,这会导致 Thymeleaf 失败并出现以下错误:

HTTP Status 500 - 请求处理失败;嵌套异常是 org.thymeleaf.exceptions.TemplateProcessingException:评估 SpringEL 表达式的异常:“#fields.hasErrors('deliverables[0].stringGrade')” (menuItems/inputGrades:33)

我想做的就是让 Thymeleaf 能够使用 #fields.HasErrors 和 #fields.error 读取值。下面是相关的代码:

成绩计算器型号:

public class GradeCalculator {

private ArrayList<Deliverable> deliverables;
Run Code Online (Sandbox Code Playgroud)

可交付模型:

@Entity
@Table(name="Deliverables")
public class Deliverable implements Serializable {


@NotEmpty(message = "Required")
@Size(min = 1, max = 100, message = "Must be between 1 and 100")
@Digits(integer = 3, fraction = 0, message = "Must be …
Run Code Online (Sandbox Code Playgroud)

spring spring-el thymeleaf

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

spring ×1

spring-el ×1

thymeleaf ×1