ClinicBindingInitializer.java
资源名称:petclinic.rar [点击查看]
上传用户:dezhong
上传日期:2022-08-10
资源大小:167k
文件大小:1k
源码类别:
Java编程
开发平台:
Java
- package org.springframework.samples.petclinic.web;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.propertyeditors.CustomDateEditor;
- import org.springframework.beans.propertyeditors.StringTrimmerEditor;
- import org.springframework.samples.petclinic.Clinic;
- import org.springframework.samples.petclinic.PetType;
- import org.springframework.web.bind.WebDataBinder;
- import org.springframework.web.bind.support.WebBindingInitializer;
- import org.springframework.web.context.request.WebRequest;
- /**
- * Shared WebBindingInitializer for PetClinic's custom editors.
- *
- * <p>Alternatively, such init-binder code may be put into
- * {@link org.springframework.web.bind.annotation.InitBinder}
- * annotated methods on the controller classes themselves.
- *
- * @author Juergen Hoeller
- */
- public class ClinicBindingInitializer implements WebBindingInitializer {
- @Autowired
- private Clinic clinic;
- public void initBinder(WebDataBinder binder, WebRequest request) {
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
- dateFormat.setLenient(false);
- binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
- binder.registerCustomEditor(String.class, new StringTrimmerEditor(false));
- binder.registerCustomEditor(PetType.class, new PetTypeEditor(this.clinic));
- }
- }