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