[英]How to get Map<String, String[]> data with @RequestParam in controller?
I have a page with many questions, and they can have multiple answers. 我的页面上有很多问题,他们可以有多个答案。
It's look like this, for every question: 对于每个问题,它看起来都是这样的:
<div th:each="answer: ${question.answers}">
<input th:type="${question.type == T(test_system.entity.QuestionType).SINGLE ? 'radio' : 'checkbox'}"
type="radio" th:name="${question.id}" th:value="${answer.id}"/>
[[${answer.text}]]
</div>
I want to get a Map<String, String[]>
in controller, which processes this request. 我想在控制器中获取
Map<String, String[]>
,该控制器处理该请求。 (key is id of question, values is answers for this question) (键是问题的ID,值是该问题的答案)
I have this code in controller: 我在控制器中有以下代码:
@RequestMapping(value = "/work/{id}/finish", method = RequestMethod.POST)
public String sendTestAnswers(@PathVariable final long id, @RequestParam final Map<String, String[]> data, final HttpServletRequest request, final Model model) {
...
}
But in data I see Map<String, String>
, with only one anwer for every question. 但是在数据中我看到
Map<String, String>
,每个问题只有一个答案。
Also in request.getParameterMap() I see Map<String, String[]>
with all values that I need. 同样在request.getParameterMap()中,我看到了
Map<String, String[]>
以及所有需要的值。
How can I bind arguments to get prepared object with all data that I need? 如何绑定参数以获取准备好的对象以及所需的所有数据? I don't want to work with HttpServletRequest directly.
我不想直接使用HttpServletRequest。
I think you should give MultiValueMap a try: http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/util/MultiValueMap.html 我认为您应该尝试MultiValueMap: http : //docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/util/MultiValueMap.html
It is better suited for these kind of data. 它更适合此类数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.