首页 > 学院 > 开发设计 > 正文

StringEscapeEditor

2019-11-11 05:16:15
字体:
来源:转载
供稿:网友
import org.sPRingframework.web.util.HtmlUtils;public class StringEscapeEditor extends PropertyEditorSupport { private boolean escapeHTML; public StringEscapeEditor() { super(); } public StringEscapeEditor(boolean escapeHTML) { super(); this.escapeHTML = escapeHTML; } @Override public void setAsText(String text) { if (text == null) { setValue(null); } else { String value = text.trim(); if (escapeHTML) { value = HtmlUtils.htmlEscape(value); } setValue(value); } } @Override public String getAsText() { Object value = getValue(); return value != null ? value.toString() : ""; }}
#
@Controllerpublic class BaseController { @InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(String.class, new StringEscapeEditor(true)); }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表