【问题标题】:Spring-boot thymeleaf fragments: Exception evaluating SpringEL expressionSpring-boot thymeleaf 片段:评估 SpringEL 表达式的异常
【发布时间】:2017-01-04 18:10:40
【问题描述】:

我在尝试从显示模式窗口的百里香片段访问 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”,如果有人可以帮助我,我将不胜感激......

【问题讨论】:

  • 你的 GirlDataVM 类有 getNickname() 方法吗?
  • 对,方法就在那里。

标签: spring controller modal-dialog thymeleaf modelandview


【解决方案1】:

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

【讨论】:

  • 还是同样的问题,对象女孩甚至没有出现在我的视野中,当我使用 th:if="${girl}" 时,输入没有出现!
  • 对不起,我没听懂你说的。在 th:if 你必须使用布尔表达式,如 th:if="${girl != null}" 或 th:if="${girl.getNickname() != null}" 和 th:text 你可以尝试这个 th:text="${girl.getNickname()}"
猜你喜欢
  • 2019-05-24
  • 2017-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-03
  • 1970-01-01
相关资源
最近更新 更多