1. 程式人生 > >前端傳參給後臺,轉資料格式

前端傳參給後臺,轉資料格式

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