全局请求参数去除空格

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));
	}
}

posted @ 2020-11-07 13:08  JaminYe  阅读(513)  评论(0编辑  收藏  举报