全局请求参数去除空格

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

作者: JaminYe
版权声明:本文原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文地址:https://www.cnblogs.com/JaminYe/p/13940697.html