gpt4 book ai didi

forms - Spring MVC 表单 Hibernate validator : Cross parameter constraint has no cross parameter validator

转载 作者:行者123 更新时间:2023-12-01 09:02:58 26 4
gpt4 key购买 nike

这是我的表格

public class TaskForm extends WebForm<TaskModel> {

public TaskForm(){
this(new TaskModel());
}

public TaskForm(TaskModel form) {
super(form);
}


@NotNull
@NotEmpty
public void setName(String taskName){
target.setTaskName(taskName);
}


@NotNull
@NotEmpty
public void setDescription(String description){
target.setDescription(description);
}

public void setStartDate(DateTime startDate){
target.setStartDate(startDate);
}

public DateTime getStartDate(){
return target.getStartDate();
}

@DateTimeFormat(pattern = "MM/dd/yyyy")
public void setEndDate(DateTime endDate){
target.setEndDate(endDate);
}

public DateTime getEndDate(){
return target.getEndDate();
}

public String getName(){
return target.getTaskName();
}

public String getDescription(){
return target.getDescription();
}
}

当我提交表单时,它向我抛出了一个异常。
HTTP Status 500 - Request processing failed; nested exception is javax.validation.ConstraintDefinitionException: HV000154: Cross parameter constraint org.hibernate.validator.constraints.NotEmpty has no cross-parameter validator.

是什么导致了这个问题?

最佳答案

尝试在 getter 中移动 @NotNull 和 @NotEmpty 验证约束。像这样改变你的表格

public class TaskForm extends WebForm<TaskModel> {

public TaskForm(){
this(new TaskModel());
}

public TaskForm(TaskModel form) {
super(form);
}

public void setName(String taskName){
target.setTaskName(taskName);
}



public void setDescription(String description){
target.setDescription(description);
}

public void setStartDate(DateTime startDate){
target.setStartDate(startDate);
}

public DateTime getStartDate(){
return target.getStartDate();
}

//@DateTimeFormat(pattern = "MM/dd/yyyy")
public void setEndDate(DateTime endDate){
target.setEndDate(endDate);
}

public DateTime getEndDate(){
return target.getEndDate();
}

@NotNull
@NotEmpty
public String getName(){
return target.getTaskName();
}

@NotNull
@NotEmpty
public String getDescription(){
return target.getDescription();
}
}

关于forms - Spring MVC 表单 Hibernate validator : Cross parameter constraint has no cross parameter validator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18169685/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com