use of com.cdeledu.core.interceptors.DateConvertEditor in project wechat by dllwh.
the class BaseController method initBinder.
/**
* ----------------------------------------------------- Fields end
*/
/**
* @方法:将前台传递过来的日期格式的字符串,自动转化为Date类型
* @创建人:独泪了无痕
* @param binder
*/
@InitBinder
public void initBinder(ServletRequestDataBinder binder) {
// String类型转换,将所有传递进来的String进行HTML编码,防止XSS攻击
binder.registerCustomEditor(String.class, new PropertyEditorSupport() {
@Override
public void setAsText(String text) {
setValue(text == null ? null : StringEscapeUtils.escapeHtml4(text.trim()));
}
@Override
public String getAsText() {
Object value = getValue();
return value != null ? value.toString() : "";
}
});
// Date 类型转换
binder.registerCustomEditor(Date.class, new DateConvertEditor());
}
Aggregations