Spring boot thymeleaf片段:计算SpringEL表达式时出现异常

Spring boot thymeleaf片段:计算SpringEL表达式时出现异常,spring,controller,modal-dialog,thymeleaf,modelandview,Spring,Controller,Modal Dialog,Thymeleaf,Modelandview,我在试图从显示模态窗口的thymeleaf片段访问ModelAndView时遇到了一个问题 这是我的index.html: <article th:each="girls : ${girlToRoot}" th:id="${girls.confirmcode}" class=" " data-status="1"> <img th:src="${girls.docProfile}" class="cover" th:alt="${girl

我在试图从显示模态窗口的thymeleaf片段访问ModelAndView时遇到了一个问题

这是我的index.html:

<article th:each="girls : ${girlToRoot}" th:id="${girls.confirmcode}" class=" " data-status="1">
                    <img th:src="${girls.docProfile}" class="cover" th:alt="${girls.nickname}"/>
                        <a href="#" th:id="${girls.confirmcode}" onclick="callroom(this.id);" data-toggle="modal" data-target="#myModal">
                            <span class="protip favorite add" data-pt-width="900" data-pt-auto-hide="2000" data-pt-classes="favorite_protip" data-pt-gravity="right 5" data-pt-size="tiny" data-pt-trigger="sticky" data-pt-arrow="false">
                            <span class="broken-heart">
                                <i class="icon-heart-broken-left"></i><i class="icon-heart-broken-right"></i>
                            </span>
                            </span>
                            <span class="performer_name" th:text="${girls.nickname}">
                            </span>
                            <span class="badge vibratoy">&nbsp;</span>
                        </a>

                </article>

<th:block th:include="/fragments/modal/messageModal :: messageModal"/>
最后,我的控制器:

@RequestMapping(value = "/getGirl", method = RequestMethod.POST)
    @ResponseBody
    public GirlDataVM getGirl(Model model, @RequestParam("confirmcode") String room){

        GirlDataVM girlDataVM = new GirlDataVM();
        girlDataVM = girlService.getByConfirmCode(room);

        ModelAndView modelAndView = new ModelAndView();
        model.addAttribute("girl", girlDataVM);
        modelAndView.addObject("girl", girlDataVM);
        modelAndView.setViewName("/fragments/modal/show :: show");

        return girlDataVM;
    }

问题是,我必须让对象girl进入模态秀,但是我收到了一个异常,评估SpringEL表达式:“girl.昵称”,如果有人能帮助我,我会很感谢…

你可以尝试调用
get昵称()
方法而不是
昵称

你的GirlDataVM类有get昵称()方法吗?是的,方法就在那里。还是同样的问题,当我使用th:if=“${girl}”时,对象女孩甚至没有出现在我的视图中,输入没有出现!对不起,我不明白你说的话。在th:if中,如果您必须使用类似th:if=“${girl!=null}”或th:if=“${girl.get昵称()!=null}”的布尔表达式,在th:text中,您可以尝试以下操作th:text=“${girl.get昵称()”
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<th:block th:fragment="show">
<input type="hidden" name="nickname" id="nickname" th:text="${girl.nickname}></input>
</html>
function callroom(room){

    $.ajax({
        type:"POST",
        url: "/getGirl",
        data: {confirmcode : room},
        cache: false,
        success: function(girl) {

        },
        error: function(response) {

        },
    });

    var messageModal = document.getElementById('myModal');
    var span = document.getElementById('close');
    messageModal.style.display = "block";

    span.onclick = function() {
        messageModal.style.display = "none";
        location.reload();

    }

}
@RequestMapping(value = "/getGirl", method = RequestMethod.POST)
    @ResponseBody
    public GirlDataVM getGirl(Model model, @RequestParam("confirmcode") String room){

        GirlDataVM girlDataVM = new GirlDataVM();
        girlDataVM = girlService.getByConfirmCode(room);

        ModelAndView modelAndView = new ModelAndView();
        model.addAttribute("girl", girlDataVM);
        modelAndView.addObject("girl", girlDataVM);
        modelAndView.setViewName("/fragments/modal/show :: show");

        return girlDataVM;
    }