SpringMVC的@InitBinder參數(shù)轉(zhuǎn)換代碼實例
更新時間:2019年09月26日 10:53:41 作者:蔡徐坤1987
這篇文章主要介紹了SpringMVC的@InitBinder參數(shù)轉(zhuǎn)換代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
這篇文章主要介紹了SpringMVC的@InitBinder參數(shù)轉(zhuǎn)換代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
@Controller @RequestMapping("/index") public class IndexController { /** * 解決前端傳遞的日期參數(shù)驗證異常 * * @param binder * @author hzj */ @InitBinder({"param", "date"})//指定校驗參數(shù) protected void initBinder(WebDataBinder binder) { // binder.setDisallowedFields("name"); // 不綁定name屬性 binder.registerCustomEditor(String.class, new StringTrimmerEditor()); // 此處使用Spring內(nèi)置的CustomDateEditor DateFormat dateFormat = 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; } }
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Spring Cloud如何使用Feign構(gòu)造多參數(shù)的請求
這篇文章主要介紹了Spring Cloud如何使用Feign構(gòu)造多參數(shù)的請求,以GET以及POST方法的請求為例進行講解,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-03-03Java連接數(shù)據(jù)庫步驟解析(Oracle、MySQL)
本文主要介紹了Java連接Oracle數(shù)據(jù)庫和MySQL數(shù)據(jù)庫的步驟解析。具有很好的參考價值,需要的朋友一起來看下吧2016-12-12spring為類的靜態(tài)屬性實現(xiàn)注入實例方法
在本篇文章里小編給大家整理的是關(guān)于spring為類的靜態(tài)屬性實現(xiàn)注入實例方法,有需要的朋友們可以參考下。2019-10-10java正則表達式表單驗證類工具類(驗證郵箱、手機號碼、qq號碼等)
這篇文章主要介紹了java使用正則表達式進行表單驗證工具類,可以驗證郵箱、手機號碼、qq號碼等方法,需要的朋友可以參考下2014-04-04詳解在Spring MVC中使用注解的方式校驗RequestParams
本篇文章主要介紹了詳解在Spring MVC中使用注解的方式校驗RequestParams ,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-03-03