使用spring控制器和不同的类在jsp中渲染数据 [英] rendering data in jsp using spring controllers and different classes

查看:75
本文介绍了使用spring控制器和不同的类在jsp中渲染数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要呈现数据

这是我的jsp页面表的外观

this is how my jsp page table look like

我如何实现这一目标

请帮助我

这让我感到困惑,要定义多少个类以及什么是字段.

it creates a lot of confusion for me, that how many classes are to be define and what are the fields.

谢谢

推荐答案

您的数据很可能来自数据库,这是返回的Javabeans List的一种.

Most likely your data is coming from database and this is kind of List of javabeans returned.

让我们说这是

List<MyObjects> objects

您需要在控制器级别进行设置:

You need to set it in controller level:

@RequestMapping(value="/table")
public ModelAndView renderTable() {
    ModelAndView mv = new ModelAndView("/table"); 
    mv.add("objects",objects);
    return mv;
}

现在这是在JSP上呈现它的方式:

Now this is the way you render it on the JSP:

<c:if test="${not empty objects}">
    <table>
        <c:forEach var="o" items="${objects}">
            <tr>
                <td>${o.id}</td>
                <td>${o.name}</td>
                <td>${o.descriptio}</td>   
            </tr>
        </c:forEach>
    </table>
</c:if>

您可以在此处了解更多信息: http://static.springsource.org/spring/docs/3.0.1.RELEASE/reference/html/view.html

You can read about it more here: http://static.springsource.org/spring/docs/3.0.1.RELEASE/reference/html/view.html

这篇关于使用spring控制器和不同的类在jsp中渲染数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆