我的JSP
<form class="repeater mx-3" id="filter-form" method="post" action="${context}/post/report2">
<div data-repeater-list="filterInputs">
<div data-repeater-item style="display:none;">
<input type="hidden" name="id" id="cat-id"/>
<div class="row mt-3">
<div class=".col-3 col-auto">
<select class="form-control search-criteria-fieldName" name="fieldName">
<option value="authorsLastName">Authors Last Name</option>
<option value="authorsAddedDate">Authors Added Date</option>
<option value="authorsBirthdate">Authors Birthdate</option>
<option value="postDate">Post Date</option>
<option value="authorsFirstName">Authors First Name</option>
<option value="title">Title</option>
<option value="postId">Post Id</option>
<option value="content">Content</option>
<option value="authorId">Author Id</option>
<option value="authorsEmail">Authors Email</option>
<option value="description">Description</option>
</select>
</div>
<div class=".col-3 col-auto">
<select class="form-control search-criteria-operator" name="oper`enter code here`ator">
<option value="equal" selected>Equal</option>
<option value="notEqual">Not Equal</option>
<option value="lessThan">LessThan</option>
<option value="lessThanOrEqual">Less Than Or Equal</option>
<option value="greater Than">Greater Than</option>
<option value="greaterThanOrEqual">Greater Than Or Equal</option>
<option value="contains">Contains</option>
<option value="containsIgnoreCase">Contains Ignore Case</option>
enter code here
<option value="notContains">Not Contains</option>
<option value="notContainsIgnoreCase">Not Contains Ignore Case</option>
<option value="beginWith">Begin With</option>
<option value="endWith">End With</option>
<option value="isNull">Is Null</option>
<option value="isNotNull">Is Not Null</option>
<option value="isEmpty">Is Empty</option>
<option value="isNotEmpty">Is Not Empty</option>
<option value="between">Between</option>
<option value="notBetween">Not Between</option>
<option value="inList">In List</option>
<option value="notInList">Not In List</option>
</select>
</div>
<div class=".col-3 col-auto">
<input type="text" class="form-control search-criteria-searchValue" name="searchValue">
</div>
<div class=".col-2 col-auto">
<select class="form-control search-criteria-conjunctionOperator"
name="conjunctionOperator">
<option value="and" selected>And</option>
<option value="or">Or</option>
<option value="notAnd">Not And</option>
<option value="notOr">Not Or</option>
</select>
</div>
<div class=".col-1 col-auto">
<input data-repeater-delete type="button" value="Delete"/>
</div>
</div>
</div>
</div>
<div class="row mt-3">
<div class=".col-4 col-auto">
<input class="" data-repeater-create type="button" value="Add Filter"/>
</div>
<div class=".col-4 col-auto">
<input class="" id="apply-filter-button" type="submit" value="Apply Filter"/>
</div>
<div class=".col-4 col-auto">
<input class="" id="reset-filter-button" type="reset" value="Reset Filter"/>
</div>
</div>
</form>
jquery转发器
$(document).ready(function () {
'use strict';
window.id = 0;
$('.repeater').repeater(
{
show: function () {
$(this).slideDown();
},
hide: function (deleteElement) {
$(this).slideUp(deleteElement);
},
defaultValues: {
'fieldName': 'authorsLastName',
'operator': 'equal',
'conjunctionOperator': 'and'
},
initEmpty: true
}
);
});
Spring Controller
@RequestMapping(value = "/post/report2", method = RequestMethod.POST)
public ModelAndView viewPostReport2(@RequestParam(value="filterInputs[][]") String[][] filterputsm, HttpServletRequest request) throws Exception {
try {
ModelAndView view = new ModelAndView("report/post-report");
return view;
} catch (Exception e) {
LOGGER.error(e.getMessage());
e.printStackTrace();
throw e;
}
}
日志
Resolved [org.springframework.web.bind.MissingServletRequestParameterException: Required String[][] parameter 'filterInputs[][]' is not present]
错误页面
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Dec 11 09:16:29 IST 2018
There was an unexpected error (type=Bad Request, status=400).
Required String[][] parameter 'filterInputs[][]' is not present
Formdata
filterInputs[0][id]:
filterInputs[0][fieldName]: authorsLastName
filterInputs[0][operator]: equal
filterInputs[0][searchValue]:
filterInputs[0][conjunctionOperator]: and
filterInputs[1][id]:
filterInputs[1][fieldName]: authorsLastName
filterInputs[1][operator]: equal
filterInputs[1][searchValue]:
filterInputs[1][conjunctionOperator]: and
filterInputs[2][id]:
filterInputs[2][fieldName]: authorsLastName
filterInputs[2][operator]: equal
filterInputs[2][searchValue]:
filterInputs[2][conjunctionOperator]: and
我面临的问题是将上述表单数据提交给spring控制器。我曾尝试使用@ModelAttribute和包装器类如下
@Data
@NoArgsConstructor
public class FilterWrapper {
List<FilterInput> filterInputs = Collections.emptyList();
}
@Data
@NoArgsConstructor
public class FilterInput {
@NotNull
private String fieldName;
@NotNull
private String operator;
@NotNull
private String searchValue;
private String conjunctionOperator;
private String id;
}
错误:Bean类[com.misyn.datatable.mapping.FilterWrapper]的无效属性'filterInputs [0] [conjunctionOperator]':非法尝试获取属性'filterInputs'引发异常;嵌套的异常是java.lang.UnsupportedOperationExceptio