「Spring」InitBinderメソットでインデックス付き配列パラメータの上限値の変更方法

説明
インデックス付き配列パラメータのデフォルトの上限値は256です。
使用例
1.クラスの定義

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
public class UserData {
protected List<Integer>idLst;
protected List<String>usrLst;
// some code
}
public class UserData { protected List<Integer>idLst; protected List<String>usrLst; // some code }
public class UserData {
   protected List<Integer>idLst;
   protected List<String>usrLst;
    // some code
}

2.@InitBinderの定義

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.setAutoGrowCollectionLimit(Integer.MAX_VALUE);
}
@InitBinder public void initBinder(WebDataBinder binder) { binder.setAutoGrowCollectionLimit(Integer.MAX_VALUE); }
@InitBinder
public void initBinder(WebDataBinder binder) {
  binder.setAutoGrowCollectionLimit(Integer.MAX_VALUE);
}

3.エラーレスポンスExceptionの処理
@ExceptionHandler(value = Exception.class)
public ModelAndVie errorHandler(HttpServletRequest req,Exception e) throws Exception
{/some code/}

SpringMVC

Posted by arkgame