PetTypeEditor.java
上传用户:dezhong
上传日期:2022-08-10
资源大小:167k
文件大小:1k
源码类别:

Java编程

开发平台:

Java

  1. package org.springframework.samples.petclinic.web;
  2. import java.beans.PropertyEditorSupport;
  3. import org.springframework.samples.petclinic.Clinic;
  4. import org.springframework.samples.petclinic.PetType;
  5. /**
  6.  * @author Mark Fisher
  7.  * @author Juergen Hoeller
  8.  */
  9. public class PetTypeEditor extends PropertyEditorSupport {
  10. private final Clinic clinic;
  11. public PetTypeEditor(Clinic clinic) {
  12. this.clinic = clinic;
  13. }
  14. @Override
  15. public void setAsText(String text) throws IllegalArgumentException {
  16. for (PetType type : this.clinic.getPetTypes()) {
  17. if (type.getName().equals(text)) {
  18. setValue(type);
  19. }
  20. }
  21. }
  22. }