SpringMVC的@InitBinder参数转换代码实例

网友投稿 233 2022-12-26


SpringMVC的@InitBinder参数转换代码实例

这篇文章主要介绍了SpringMVC的@InitBinder参数转换代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

@Controller

@RequestMapping("/index")

public class IndexController {

/**

* 解决前端传递的日期参数验证异常

*

* @param binder

* @author hzj

*/

@InitBinder({"param", "date"})//指定校验参数

protected void initBinder(WebDataBinder binder) {

// binder.setDisallowedFields("name"); // 不绑定name属性

binder.registerCustomEditor(String.class, new StringTrimmerEditor());

// 此处使用Spring内置的CustomDateEditor

DateFormat dathttp://eFormat = new SimpleDateFormat("yyyy-MM-dd");

binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));

}

@ResponseBody

@GetMapping("/initbinder")

public String testInitBinder(String param, Date date) {

return param + ":" + date;

}

}


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:intellij idea 启动tomcat 1099端口被占用的解决
下一篇:支付宝接口测试工具(支付接口怎么测试)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~