当条件为:如果为真,则不显示百日咳块

时间:2018-04-25 04:13:56

标签: java html thymeleaf

我在这里有一个街区:

<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>

和控制器是

@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”但块未显示。为什么?有人帮帮我吗?

更新 VIEW_REDIRECT_FIND_GUIDE是

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

和/ operator / searchguide的控制器是:

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";

1 个答案:

答案 0 :(得分:0)

正如我在之前的评论中所说,您必须使用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;
}