gpt4 book ai didi

java - 当 :if is true 的条件时, thymeleaf block 不显示

转载 作者:太空宇宙 更新时间:2023-11-04 10:30:52 25 4
gpt4 key购买 nike

我这里有一个 block :

<th:block th:if= "${not #lists.isEmpty(listGuide)}">
<table class="table" style="margin-left: 100px" >
<thead>
<tr>
<td><b>Tên</b></td>
<td><b>Địa chỉ</b></td>
<td><b>Phone</b></td>
<td><b>Kinh nghiệm</b></td>
</tr>
</thead>
</table>
</th:block>

Controller 是

@PostMapping("/operator/search")
public String searchGuide(HttpServletRequest request, Model model) {
String location = request.getParameter(Constant.PARAMETER_LOCATION);
String language = request.getParameter(Constant.PARAMETER_LANGUAGE);
String gender = request.getParameter(Constant.PARAMETER_GENDER);
String type = request.getParameter(Constant.PARAMETER_TYPE);
model.addAttribute("listGuide",
operatorService.findGuide(location, gender, type, language));
log.info("size list guide search: "
+ operatorService.findGuide(location, gender, type, language).size());
return Constant.VIEW_REDIRECT_FIND_GUIDE;
}

此日志“尺寸列表指南搜索:19901”但 block 不显示。为什么?有人帮助我吗?

更新VIEW_REDIRECT_FIND_GUIDE 是

public static final String VIEW_REDIRECT_FIND_GUIDE = "redirect:/operator/searchguide";

/operator/searchguide 的 Controller 是:

public String findGuide(HttpServletRequest request, Model model) {
Principal principal = request.getUserPrincipal();
User user = userDetailService.findByUsername(principal.getName());
Operator operator = operatorService.findByUserId(user.getId());
model.addAttribute(Constant.ENTITIY_OPERATOR, operator);
model.addAttribute(Constant.ENTITIY_LIST_LANGUAE, (List<Language>) languageService.findAll());
model.addAttribute(Constant.ENTITIY_LIST_LOCATION, (List<Location>) locationService.findAll());
return "find-guider";

最佳答案

正如我在之前的评论中所说,您必须使用 Flash Scope,因为您要重定向到页面。尝试如下所示

@PostMapping("/operator/search")
public String searchGuide(HttpServletRequest request, RedirectAttributes attributes) {
String location = request.getParameter(Constant.PARAMETER_LOCATION);
String language = request.getParameter(Constant.PARAMETER_LANGUAGE);
String gender = request.getParameter(Constant.PARAMETER_GENDER);
String type = request.getParameter(Constant.PARAMETER_TYPE);
//model.addAttribute("listGuide", operatorService.findGuide(location, gender, type, language));
attributes.addFlashAttribute("listGuide",peratorService.findGuide(location, gender, type, language));
log.info("size list guide search: "
+ operatorService.findGuide(location, gender, type, language).size());
return Constant.VIEW_REDIRECT_FIND_GUIDE;
}

关于java - 当 :if is true 的条件时, thymeleaf block 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50013961/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com