将多维数组请求参数发送到服务器

时间:2017-04-09 09:45:26

标签: spring spring-mvc servlets java-ee datatables

基本上我不会这样做,如果我在前端有控制权,但当我使用DataTable ajax功能时,他们会发布如下数据:

columns[0][data]:0
columns[0][name]:
columns[0][searchable]:true
columns[0][orderable]:true
columns[0][search][value]:
columns[0][search][regex]:false
columns[1][data]:1
columns[1][name]:
columns[1][searchable]:true
columns[1][orderable]:true
columns[1][search][value]:
columns[1][search][regex]:false
columns[2][data]:2
columns[2][name]:
columns[2][searchable]:true
columns[2][orderable]:true
columns[2][search][value]:
columns[2][search][regex]:false
columns[3][data]:3
columns[3][name]:
columns[3][searchable]:true
columns[3][orderable]:true
columns[3][search][value]:
columns[3][search][regex]:false
columns[4][data]:4
columns[4][name]:

我有两个问题:

1)如何在servlet中相应地检索值? getParameterValues只能得到一维数组,我不知道如何检索上面的例子。

2)如果我使用Spring MVC,如何检索该值?

1 个答案:

答案 0 :(得分:0)

OK, I roughly found the answer although it is not perfect:

1) I am confused about the array parameters, in fact, posting the data as above, it is not array parameters, I can purely extract the value via string, like this.

2) For Spring MVC, I still can't find a way to convert request to an object, so for simplicity, I rather to receive the request param in @RequestParam Map<String, String> params, and iterate over each key. (Thanks @Nikos Paraskevopoulos for highlighting)