在controller类中
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(String.class, new StringFormat());
}
class StringFormat extends PropertyEditorSupport{
//text时前端传的参数值
//setValue设置参数传到后台时的值
@Override
public void setAsText(String text) throws IllegalArgumentException {
if(text == ""){
setValue("为空");
}else{
setValue(text);
}
}
}