SpringMVC的@InitBinder参数转换代码实例
这篇文章主要介绍了SpringMVC的@InitBinder参数转换代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
@Controller
@RequestMapping("/index")
publicclassIndexController{
/**
*解决前端传递的日期参数验证异常
*
*@parambinder
*@authorhzj
*/
@InitBinder({"param","date"})//指定校验参数
protectedvoidinitBinder(WebDataBinderbinder){
//binder.setDisallowedFields("name");//不绑定name属性
binder.registerCustomEditor(String.class,newStringTrimmerEditor());
//此处使用Spring内置的CustomDateEditor
DateFormatdateFormat=newSimpleDateFormat("yyyy-MM-dd");
binder.registerCustomEditor(Date.class,newCustomDateEditor(dateFormat,true));
}
@ResponseBody
@GetMapping("/initbinder")
publicStringtestInitBinder(Stringparam,Datedate){
returnparam+":"+date;
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。