請幫我在這。從視圖頁面傳遞對象到Spring控制器
我需要從視圖頁面傳遞一個複雜的對象到Spring控制器......我想使用的ModelAttribute(查看頁面使用thymeleaf內置+ HTML)..
我的問題是該對象是作爲傳遞字符串,而不是實際的對象,這會在控制器端造成異常。在下面的例如「類別」是一個複雜的對象,其中包含list,array,String和其他對象作爲變量。類別作爲字符串而不是對象本身傳遞。如何將此對象傳遞給控制器。
@Controller
public class QController extends WZController{
@RequestMapping(value = "/refreshfacets")
public String refreshfacets(HttpServletRequest request, HttpServletResponse response, Model model,
@ModelAttribute("refreshFacetsRequest") refreshFacetsRequestDTO refreshfacetsrequest) throws Exception {
Map<String, Object> responseMap = new HashMap<String, Object>();
ProductSearchResult productsearchresult = new ProductSearchResult();
//super.refreshFacets(request, response, model, productsearchresult);
return XXXX;
}
}
public class refreshFacetsRequestDTO {
private static final long serialVersionUID = 1L;
private Category category;
private String state;
private String program;
private String subject;
private String year;
private String price;
Constructor, getter, setter methods;
}
<div th:remove="tag">
<form method="post" id="form1" th:action="@{/refreshfacets}" th:object="${refreshFacetsRequest}">
<input type="hidden" id="category" name="category" th:if="${category}" th:value="${category}"/>
<input type="text" id="state" name="state" th:if="${state}" th:value="${state}"/>
<input type="text" id="program" name="program" th:if="${program}" th:value="${program}"/>
<input type="text" id="subject" name="subject" th:if="${subject}" th:value="${subject}"/>
<input type="submit" th:attr="onsubmit=${'doAjaxPost()'}"></input>
</form>
</div>
請對此建議。除了要傳遞對象的模型屬性以外的其他任何選項也可以。如果是的話請詳細說明烏爾其他選項
我不知道是什麼'日:表單標籤:object'做,但彈簧模型屬性對象只帶彈簧的工作。 –
@BhashitParikh'th'前綴是'Thymeleaf'。我們可以假設OP正在使用'ThymeleafViewResolver'。模型屬性最終在請求屬性中,所以它們在那裏也可用。 –
@SotiriosDelimanolis u能幫助我在這...模型屬性作爲字符串傳遞,我希望它是對象... – user1611575