我有一个名为“cutleryCustomerSearch”的视图,其中包含(替换)一个片段:
<div id="content">
<div th:replace="fragments/customerSearch :: customerSearch"></div>
</div>
在此片段中,我有一个表,我喜欢通过 ajax 更新它:
<table id="customersTable" th:fragment="customersTable">
我如何设置处理 ajax 请求的控制器方法的返回?目前我有(不起作用):
return "cutleryCustomerSearch :: customerSearch/customersTable";
但它不设置内容,只是删除表。
它工作得很好,直到我将“customerSearch”碎片化。
这是我的ajax请求:
$.ajax({
type : 'POST',
cache : false,
url : form.attr('action'),
data : form.serialize(),
success : function(data) {
$("#customersTable").html(data);
}
});
我在这篇博文中找到了一个例子:Thymeleaf 与 Spring 集成(第 2 部分) http://www.javacodegeeks.com/2014/03/thymeleaf-integration-with-spring-part-2.html.
Spring MVC 的控制器 http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-controller将返回字符串"results :: resultsList"
, 像这样 :
@RequestMapping(value = "/guests", method = RequestMethod.GET)
public String showGuestList(Model model) {
model.addAttribute("guests", hotelService.getGuestsList());
return "results :: resultsList";
}
在“结果”页面中,将有一个名为“resultsList”的块(片段),如下例所示:
<div th:fragment="resultsList" th:unless="${#lists.isEmpty(guests)}" class="results-block">
<table>
<thead>
<tr>
<th th:text="#{results.guest.id}">Id</th>
<th th:text="#{results.guest.surname}">Surname</th>
<th th:text="#{results.guest.name}">Name</th>
<th th:text="#{results.guest.country}">Country</th>
</tr>
</thead>
<tbody>
<tr th:each="guest : ${guests}">
<td th:text="${guest.id}">id</td>
<td th:text="${guest.surname}">surname</td>
<td th:text="${guest.name}">name</td>
<td th:text="${guest.country}">country</td>
</tr>
</tbody>
</table>
</div>
它应该有帮助...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)