不要在 jsp jstl 上显示来自控制器的信息

Do not display information from the controller on jsp jstl

我使用 jstl 在 jsp 页面上显示数据时遇到问题。

这是我的页面,显示信息:

EMPTY !!!
Name    Email   Action

get-user.jsp

<html>
    <head>
        <title>All users</title>
    </head>
    <body>
        <c:if test="${empty webModels}">
            <h3>EMPTY !!!</h3>
        </c:if>
            <table>
                <thead>
                <tr>
                    <th>Name</th>
                    <th>Email</th>
                    <th>Action</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach items="${webModels}" var="web">
                    <tr>
                        <td>${web.userName}</td>
                        <td>${web.userEmail}</td>
                        <td>${web.Action}</td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
    </body>
</html>

控制器打印信息大小4

@RequestMapping(value = "/get-user", method = RequestMethod.GET)
public List<WebModel> getWebModels(){
    List<WebModel> webModels = serviceWeb.getAllUser();
    System.out.println(webModels.size()); //not empty
    return webModels;
}

WebModel 我从一些数据库中获取数据 table 和我在 WebModel

中设置的主要数据
public class WebModel {
    private String userName;
    private String userEmail;
    private String Action;
    //getter setter constructor
}

documentation about return types of controller methods 说:

Any other return type is considered to be a single model attribute to be exposed to the view, using the attribute name specified through @ModelAttribute at the method level (or the default attribute name based on the return type class name). The model is implicitly enriched with command objects and the results of @ModelAttribute annotated reference data accessor methods.

所以,如果我没看错的话,你应该在你的 JSP 中使用 list 而不是 webModels,或者你应该用

注释方法
@ModelAttribute("webModels")