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

Java编程

开发平台:

Java

  1. package org.springframework.samples.petclinic.web;
  2. import java.text.SimpleDateFormat;
  3. import java.util.Date;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.beans.propertyeditors.CustomDateEditor;
  6. import org.springframework.beans.propertyeditors.StringTrimmerEditor;
  7. import org.springframework.samples.petclinic.Clinic;
  8. import org.springframework.samples.petclinic.PetType;
  9. import org.springframework.web.bind.WebDataBinder;
  10. import org.springframework.web.bind.support.WebBindingInitializer;
  11. import org.springframework.web.context.request.WebRequest;
  12. /**
  13.  * Shared WebBindingInitializer for PetClinic's custom editors.
  14.  *
  15.  * <p>Alternatively, such init-binder code may be put into
  16.  * {@link org.springframework.web.bind.annotation.InitBinder}
  17.  * annotated methods on the controller classes themselves.
  18.  *
  19.  * @author Juergen Hoeller
  20.  */
  21. public class ClinicBindingInitializer implements WebBindingInitializer {
  22. @Autowired
  23. private Clinic clinic;
  24. public void initBinder(WebDataBinder binder, WebRequest request) {
  25. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  26. dateFormat.setLenient(false);
  27. binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
  28. binder.registerCustomEditor(String.class, new StringTrimmerEditor(false));
  29. binder.registerCustomEditor(PetType.class, new PetTypeEditor(this.clinic));
  30. }
  31. }