Java 验证表单时未显示错误消息
因此,我必须制作一个应用程序,在其中你有一个鸟类物种列表,你可以在列表中添加新的鸟类。此表单需要进行一些验证,但由于某些原因,没有显示错误消息。此外,当您正确输入所有输入时,一切正常,但当您输入错误时,它应该只会再次显示同一页面,但它会返回一个白标签错误 下面是我的模型类和验证:Java 验证表单时未显示错误消息,java,spring-boot,Java,Spring Boot,因此,我必须制作一个应用程序,在其中你有一个鸟类物种列表,你可以在列表中添加新的鸟类。此表单需要进行一些验证,但由于某些原因,没有显示错误消息。此外,当您正确输入所有输入时,一切正常,但当您输入错误时,它应该只会再次显示同一页面,但它会返回一个白标签错误 下面是我的模型类和验证: public class BirdSpecie { @NotEmpty(message="This input may not be empty") private String name; @No
public class BirdSpecie {
@NotEmpty(message="This input may not be empty")
private String name;
@NotNull(message="This input may not be empty")
@DecimalMin(value="1250", message="The earliest year of discovery allowed is 1250")
private Integer yearOfDiscovery;
@NotEmpty(message="This input may not be empty")
@Pattern(regexp= "^[A-Z]{1,2}[0-9]{3}$", message="Code should start with one or more capital letters [A-Z] followed by 3 digits")
private String code;
以下是我的控制器方法:
@PostMapping(value="/{locationName}/addBirdSpecie")
public String onSubmit (
@PathVariable("locationName")String locationName,
@Valid @ModelAttribute("spottedBirdSpecie") BirdSpecie birdSpecie,
Model model, BindingResult result)
{
model.addAttribute("spottedBirdSpecie", birdSpecie);
BirdSpotLocation birdSpotLocation = spottedBirdService.findByName(locationName).get();
yearValidation.validate(birdSpecie,result);
if(result.hasErrors()) {
return "addSpecie";
}else {
birdSpotLocation.increaseBirdSpot(birdSpecie);
model.addAttribute("location", birdSpotLocation);
return "birdsList";
}
}
这是我的jsp文件:
创建一个新的鸟类物种
创建新的鸟类物种:
种类:
发现年份:
鸟类书籍代码: