2017-12-04 14 views
0

Spring MVCコントローラでPostパラメータを取得しようとしていますが、ServletRequestUtils getStringParametersメソッドがこのパラメータを検出できず、空の配列を返します。 ServletRequestUtilsで配列パラメータを取得する方法はありますか?Spring MVCコントローラでPostパラメータを取得するには?

マイコントローラ;

@ResponseBody 
@RequestMapping(value = "/update", method = RequestMethod.POST) 
public String update(HttpServletRequest request, HttpServletResponse response){ 

    //I can get id parameter without problem. 
    String id = ServletRequestUtils.getStringParameter(request, "id", null); 

    String[] types = ServletRequestUtils.getStringParameters(request, "types"); 
} 

My ajax post;

$.post("update", { 
    id: id, 
    types: types 
    .... 
} 

私のフォームデータ。

id=2a4e905d-8015-447c-9d52-896042367c8a&types%5B%5D=IP+Num&types%5B%5D=Ver+Tab 

答えて

3

伝統追加してみてください:本当この

$.ajax({ 
     url:'update', 
     type:'post', 
     data:{ 
       id: id,  
       types:types, 
       .... 
       }, 
      traditional:true 
     }) 

それとも

$.post("update", $.param({ 
    id: id,  
    types:types, 
    .... 
    },true) 

} 
+0

のようなオプションにまだパラメータを見つけることができません。 – hellzone

+0

申し訳ありませんが、私は答えを更新しました。今回はうまくいくと確信しています – neo

+0

私の$ .postメソッドを$ .ajaxメソッドに更新しました。 – hellzone

関連する問題