package com.ustcinfo.fn.config;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.support.WebBindingInitializer;
<!--more-->
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 全局请求参数去除空格 string转date
*
* @author Jamin
* @date 2020/9/21 17:03
*/
@ControllerAdvice
public class MyStringTrimmerEditor implements WebBindingInitializer {
@Override
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
simpleDateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(simpleDateFormat, true));
binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
}
}