1 使用步骤
A 扩展点 Controller中增加
@InitBinder
@Override
public void initBinder(WebDataBinder binder) {
super.initBinder(binder);
// http post 请求中属性变量的自定义编辑器
binder.registerCustomEditor(Integer.class, "需要修改的变量名",new MyEditor());
}
B MyEditor
public class MyEditor extends PropertyEditorSupport {
@Override
public void setAsText(String text) throws IllegalArgumentException {
if (StringUtils.hasText(text)) {
setValue(text);
} else {
setValue(null);
}
}
@Override
public Object getValue() {
//当变量为字符串"null"时 转换为null
if("null".equals(super.getValue())){
return null;
}
return super.getValue();
}
}
C 作用范围 controller中相关的每次http请求