@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor( Long.class, new CustomNumberEditor(Long.class, true)); binder.registerCustomEditor( Double.class, new CustomNumberEditor(Double.class, true)); binder.registerCustomEditor( BigDecimal.class, new CustomNumberEditor( BigDecimal.class, new DecimalFormat("#,##0.00"), true)); binder.registerCustomEditor( Boolean.class, new CustomBooleanEditor(true)); binder.registerCustomEditor( Date.class, new CustomDateEditor(new SimpleDateFormat("dd/MM/yyyy"), true)); binder.registerCustomEditor( Object.class, new ObjectTypeEditorHelper()); }
@InitBinder("employeeForm") public void initBinder(WebDataBinder binder){ binder.setValidator(employeeValidator); binder.registerCustomEditor(Date.class, new DateEditor()); binder.registerCustomEditor(Integer.class, "age", new AgeEditor()); }
@InitBinder public void initBinder(WebDataBinder binder) { binder.setAutoGrowNestedPaths(false); binder.registerCustomEditor( Long.class, new CustomNumberEditor(Long.class, true)); binder.registerCustomEditor( Double.class, new CustomNumberEditor(Double.class, true)); binder.registerCustomEditor( BigDecimal.class, new CustomNumberEditor( BigDecimal.class, new DecimalFormat("#,##0.00"), true)); binder.registerCustomEditor( Boolean.class, new CustomBooleanEditor(true)); binder.registerCustomEditor( Date.class, new CustomDateEditor(new SimpleDateFormat("dd/MM/yyyy"), true)); binder.registerCustomEditor( Object.class, new ObjectTypeEditorHelper()); }
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor( byte[].class, new ByteArrayMultipartFileEditor()); binder.registerCustomEditor( Date.class, new CustomDateEditor(new SimpleDateFormat("dd/MM/yyyy"), true)); binder.registerCustomEditor( Long.class, new CustomNumberEditor(Long.class, true)); binder.registerCustomEditor( Double.class, new CustomNumberEditor(Double.class, true)); binder.registerCustomEditor( BigDecimal.class, new CustomNumberEditor( BigDecimal.class, new DecimalFormat("#,##0.00"), true)); binder.registerCustomEditor( Boolean.class, new CustomBooleanEditor(false)); }
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor( Long.class, new CustomNumberEditor(Long.class, true)); binder.registerCustomEditor( Double.class, new CustomNumberEditor(Double.class, true)); binder.registerCustomEditor( BigDecimal.class, new CustomNumberEditor( BigDecimal.class, new DecimalFormat("#,##0.00"), true)); binder.registerCustomEditor( Boolean.class, new CustomBooleanEditor(false)); binder.registerCustomEditor( Date.class, new CustomDateEditor(new SimpleDateFormat("dd/MM/yyyy"), true)); }
/*** * @param binder * @InitBinder 用来配置全局 Controller ,设置 WebDataBinder,WebDataBinder 用来自动绑定前台请求参数到 Model 中。 */ @InitBinder public void initBinder(WebDataBinder binder) { //忽略 request 中的参数 dis ,更多关于 WebDataBinder ,可参考文档。 //binder.setDisallowedFields("dis"); // binder.registerCustomEditor(LocalDate.class, new PropertyEditorSupport() { // @Override // public void setAsText(String text) throws IllegalArgumentException { // LocalDate.parse(text, DateTimeFormatter.ISO_DATE); // } // }); //自动绑定 LocalDate // // @GetMapping // public ResponseEntity<List<Order>> getOrdersByDate( // @RequestParam(name = "date")LocalDate date) { // // retrieve and return orders by date // } }
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(SignatureForm.class, new EnumPropertyEditor(SignatureForm.class)); binder.registerCustomEditor(ASiCContainerType.class, new EnumPropertyEditor(ASiCContainerType.class)); binder.registerCustomEditor(SignatureLevel.class, new EnumPropertyEditor(SignatureLevel.class)); binder.registerCustomEditor(DigestAlgorithm.class, new EnumPropertyEditor(DigestAlgorithm.class)); binder.registerCustomEditor(EncryptionAlgorithm.class, new EnumPropertyEditor(EncryptionAlgorithm.class)); }
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(SignatureForm.class, new EnumPropertyEditor(SignatureForm.class)); binder.registerCustomEditor(ASiCContainerType.class, new EnumPropertyEditor(ASiCContainerType.class)); binder.registerCustomEditor(SignaturePackaging.class, new EnumPropertyEditor(SignaturePackaging.class)); binder.registerCustomEditor(SignatureLevel.class, new EnumPropertyEditor(SignatureLevel.class)); binder.registerCustomEditor(DigestAlgorithm.class, new EnumPropertyEditor(DigestAlgorithm.class)); binder.registerCustomEditor(EncryptionAlgorithm.class, new EnumPropertyEditor(EncryptionAlgorithm.class)); }
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(ASiCContainerType.class, new EnumPropertyEditor(ASiCContainerType.class)); binder.registerCustomEditor(SignatureForm.class, new EnumPropertyEditor(SignatureForm.class)); binder.registerCustomEditor(SignaturePackaging.class, new EnumPropertyEditor(SignaturePackaging.class)); binder.registerCustomEditor(SignatureLevel.class, new EnumPropertyEditor(SignatureLevel.class)); }
@InitBinder protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { binder.registerCustomEditor(Category.class, "categorySet", new PropertyEditorSupport() { @Override public void setAsText(String text) { Category category = categoryService.findByPK(Long.parseLong(text)); setValue(category); } }); }
@InitBinder protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { binder.registerCustomEditor(Role.class, "roles", new PropertyEditorSupport() { @Override public void setAsText(String text) { Role role = roleService.findByPK(Long.parseLong(text)); setValue(role); } }); }
protected void initBinder(Object handler, String attrName, WebDataBinder binder, NativeWebRequest webRequest) throws Exception { if (this.bindingInitializer != null) { this.bindingInitializer.initBinder(binder, webRequest); } if (handler != null) { Set<Method> initBinderMethods = this.methodResolver.getInitBinderMethods(); if (!initBinderMethods.isEmpty()) { boolean debug = logger.isDebugEnabled(); for (Method initBinderMethod : initBinderMethods) { Method methodToInvoke = BridgeMethodResolver.findBridgedMethod(initBinderMethod); String[] targetNames = AnnotationUtils.findAnnotation(initBinderMethod, InitBinder.class).value(); if (targetNames.length == 0 || Arrays.asList(targetNames).contains(attrName)) { Object[] initBinderArgs = resolveInitBinderArguments(handler, methodToInvoke, binder, webRequest); if (debug) { logger.debug("Invoking init-binder method: " + methodToInvoke); } ReflectionUtils.makeAccessible(methodToInvoke); Object returnValue = methodToInvoke.invoke(handler, initBinderArgs); if (returnValue != null) { throw new IllegalStateException( "InitBinder methods must not have a return value: " + methodToInvoke); } } } } } }
@InitBinder protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) { binder.registerCustomEditor(Role.class, "roles", new PropertyEditorSupport() { @Override public void setAsText(String text) { Role role = roleService.findByPK(Long.parseLong(text)); setValue(role); } }); }
@InitBinder public void initBinder(ServletRequestDataBinder binder) { /** * 自动转换日期类型的字段格式 */ binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), true)); /** * 防止XSS攻击 */ binder.registerCustomEditor(String.class, new StringEscapeEditor()); }
@InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat( TodoListUtils.DATE_FORMAT); binder.registerCustomEditor(Date.class, new CustomDateEditor( dateFormat, false)); binder.registerCustomEditor(Priority.class, new TodoPriorityPropertyEditor()); }
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor( byte[].class, new ByteArrayMultipartFileEditor()); binder.registerCustomEditor( Date.class, new CustomDateEditor(new SimpleDateFormat("dd/MM/yyyy"), true)); binder.registerCustomEditor( Long.class, new CustomNumberEditor(Long.class, true)); binder.registerCustomEditor( Double.class, new CustomNumberEditor(Double.class, true)); binder.registerCustomEditor( BigDecimal.class, new CustomNumberEditor( BigDecimal.class, new DecimalFormat("#,##0.00"), true)); binder.registerCustomEditor( Boolean.class, new CustomBooleanEditor(false)); binder.registerCustomEditor( Object.class, new ObjectTypeEditorHelper()); }
/** * Registers the {@link StringTrimmerEditor} * * @param webDataBinder */ @InitBinder public void initBinder(WebDataBinder webDataBinder) { StringTrimmerEditor trimmer = new StringTrimmerEditor(this.getCharsToDelete(), this.isEmptyAsNull()); webDataBinder.registerCustomEditor(String.class, trimmer); }
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); }
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); binder.registerCustomEditor( Object.class, new ObjectTypeEditorHelper()); }
@InitBinder public void initBinder(WebDataBinder binder, WebRequest request) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); binder.registerCustomEditor(java.util.Date.class, new CustomDateEditor( dateFormat, true)); }
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor( boolean.class, new CustomBooleanEditor(false)); binder.registerCustomEditor( Date.class, new CustomDateEditor(new SimpleDateFormat("dd/MM/yyyy"), true)); }
@SuppressWarnings("unused") @InitBinder({"myCommand", "date"}) private void initBinder(WebDataBinder binder, String date, @RequestParam("date") String[] date2) { LocalValidatorFactoryBean vf = new LocalValidatorFactoryBean(); vf.afterPropertiesSet(); binder.setValidator(vf); assertEquals("2007-10-02", date); assertEquals(1, date2.length); assertEquals("2007-10-02", date2[0]); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); }
/** * 表单中其他格式传入前先解析 * 如时间类型 * @param request * @param binder * @throws Exception */ @InitBinder protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { //对于需要转换为Date类型的属性,使用DateEditor进行处理 binder.registerCustomEditor(Date.class, new DateEditor()); //获取实体类,然后初始化去获取其特定的转换方式 IBaseDomain baseDomain=(IBaseDomain)getServiceImp().getBaseDao().getDomainClass().newInstance(); baseDomain.convertFields( request, binder); }
@InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); sdf.setLenient(true); binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true)); binder.setValidator(this.validator); }
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); Object target = binder.getTarget(); if (target != null) { binder.replaceValidators(supportedValidatorsFor(target.getClass())); } }
@SuppressWarnings("unused") @InitBinder private void initBinder(WebDataBinder binder) { binder.initBeanPropertyAccess(); binder.setRequiredFields("sex"); LocalValidatorFactoryBean vf = new LocalValidatorFactoryBean(); vf.afterPropertiesSet(); binder.setValidator(vf); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); }
@InitBinder("personForm") public void initBinder(WebDataBinder binder) { binder.setValidator(personalValidator); binder.registerCustomEditor(Integer.class, "biography.age", new AgeConverter()); binder.registerCustomEditor(Integer.class, "education.year", new YearConverter()); binder.registerCustomEditor(Date.class, "biography.birthDate", new BirthDateConverter()); }
@InitBinder public void initBinder(WebDataBinder binder, @PathVariable("hotel") String hotel) { assertEquals("Invalid path variable value", "42", hotel); binder.initBeanPropertyAccess(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); }
@InitBinder public void initWebDataBinder(WebDataBinder webDataBinder) { webDataBinder.registerCustomEditor(MadeBy.class, new MadeByEnumConverter()); }
@InitBinder("employeeForm") public void initBinder(WebDataBinder binder){ binder.registerCustomEditor(Integer.class, "age", new AgeEditor()); binder.registerCustomEditor(Date.class, new DateEditor()); }