0

我在尝试从显示模式窗口的百里香片段中访问 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"/>

这是消息模式的片段:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<!--  Modal window to message  users -->
<th:block th:fragment="messageModal">

    <div id="myModal" class="modal fade">
        <div class="modal-body">
            <span class="close" id="close">Fechar ×</span>
            <th:block th:replace="/fragments/modal/show :: show"></th:block>
        </div>
    </div>
</th:block>
</html>

在这里,我们有上面代码中列出的片段显示:

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

这是我的 js,它制作了一个 ajax 来获取 ModelAndView 并打开模式:

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

问题是,我必须让对象女孩进入模态显示,但我收到了评估 SpringEL 表达式的异常:“girl.nickname”,如果有人可以帮助我,我将不胜感激......

4

1 回答 1

0

您可以尝试调用该getNickname()方法而不是nickname

于 2017-01-09T11:32:07.883 回答