PetValidator.java
资源名称:petclinic.rar [点击查看]
上传用户:dezhong
上传日期:2022-08-10
资源大小:167k
文件大小:1k
源码类别:
Java编程
开发平台:
Java
- package org.springframework.samples.petclinic.validation;
- import org.springframework.samples.petclinic.Pet;
- import org.springframework.util.StringUtils;
- import org.springframework.validation.Errors;
- /**
- * <code>Validator</code> for <code>Pet</code> forms.
- *
- * @author Ken Krebs
- * @author Juergen Hoeller
- */
- public class PetValidator {
- public void validate(Pet pet, Errors errors) {
- String name = pet.getName();
- if (!StringUtils.hasLength(name)) {
- errors.rejectValue("name", "required", "required");
- }
- else if (pet.isNew() && pet.getOwner().getPet(name, true) != null) {
- errors.rejectValue("name", "duplicate", "already exists");
- }
- }
- }