如何将postgreSQL的数据导入到Struts2-jquery-grid?

发布于 2024-12-26 10:33:41 字数 2184 浏览 0 评论 0原文

我有一个数据库,可以使用struts和jsp看到完整的HTML表格。

现在,我想使用相同的数据配置 struts2-jquery-grid。有人可以帮助我吗?我找了好几天了,没找到这个任务。

这是我的操作:

    package sead.painel.actions.dpp;

    import java.util.List;

    import org.apache.struts2.convention.annotation.Action;
    import org.apache.struts2.convention.annotation.ParentPackage;
    import org.apache.struts2.convention.annotation.Result;
    import sead.painel.dao.ConcursoDAO;
    import sead.painel.modelo.dpp.Concurso;

    import com.opensymphony.xwork2.ActionSupport;

    @ParentPackage("default")
    public class ListaConcursos extends ActionSupport {
       /**
       * 
       */
       private static final long serialVersionUID = 1L;
       private List<Concurso> concursos;


       @Action(value="lista-concursos", results={
        @Result(name="success", location="lista-concursos.jsp")
       })


       public String execute(){    

       concursos = new ConcursoDAO().getLista();
       return "success";
       }

       public List<Concurso> getConcursos() {
       return concursos;
       }

       public void setConcursos(List<Concurso> concursos) {
       this.concursos = concursos;
       }
    }

这里是 jsp:

    <%@taglib prefix="sj" uri="/struts-jquery-tags" %>
    <%@taglib prefix="s" uri="/struts-tags" %>
    <%@taglib prefix="sjg" uri="/struts-jquery-grid-tags" %>

    <head>
    <sj:head jqueryui="true" jquerytheme="redmond" />
    </head>

    <sj:a href="dpp/concursos" targets="tone">Voltar</sj:a>

    <s:url action="lista-concursos" id="listaConcursos" />

    <sjg:grid 

    gridModel="dpp/lista-concursos" 
    href="%{listaConcursos}"
    caption="Lista de Concursos"
    rowList="10, 15, 20"
    rowNum="10"
    rownumbers="true"
    pager="true"
    dataType="json">

    <sjg:gridColumn name="nome" index="nome" title="Nome" dataType="text" value="#concurso.nome" />
    <sjg:gridColumn name="codigo" index="codigo" title="Codigo" dataType="json" value="#concurso.codigo" />


</sjg:grid>

网格不加载任何内容。但我可以使用 .html 文件加载 HTML 表中的数据。

I have a database and can see a complete HTML table using struts and jsp.

Now, I would want to configure a struts2-jquery-grid with the same data. Could someone help me? I have been searching for days and couldn't find this task.

Here is my action:

    package sead.painel.actions.dpp;

    import java.util.List;

    import org.apache.struts2.convention.annotation.Action;
    import org.apache.struts2.convention.annotation.ParentPackage;
    import org.apache.struts2.convention.annotation.Result;
    import sead.painel.dao.ConcursoDAO;
    import sead.painel.modelo.dpp.Concurso;

    import com.opensymphony.xwork2.ActionSupport;

    @ParentPackage("default")
    public class ListaConcursos extends ActionSupport {
       /**
       * 
       */
       private static final long serialVersionUID = 1L;
       private List<Concurso> concursos;


       @Action(value="lista-concursos", results={
        @Result(name="success", location="lista-concursos.jsp")
       })


       public String execute(){    

       concursos = new ConcursoDAO().getLista();
       return "success";
       }

       public List<Concurso> getConcursos() {
       return concursos;
       }

       public void setConcursos(List<Concurso> concursos) {
       this.concursos = concursos;
       }
    }

And here the jsp:

    <%@taglib prefix="sj" uri="/struts-jquery-tags" %>
    <%@taglib prefix="s" uri="/struts-tags" %>
    <%@taglib prefix="sjg" uri="/struts-jquery-grid-tags" %>

    <head>
    <sj:head jqueryui="true" jquerytheme="redmond" />
    </head>

    <sj:a href="dpp/concursos" targets="tone">Voltar</sj:a>

    <s:url action="lista-concursos" id="listaConcursos" />

    <sjg:grid 

    gridModel="dpp/lista-concursos" 
    href="%{listaConcursos}"
    caption="Lista de Concursos"
    rowList="10, 15, 20"
    rowNum="10"
    rownumbers="true"
    pager="true"
    dataType="json">

    <sjg:gridColumn name="nome" index="nome" title="Nome" dataType="text" value="#concurso.nome" />
    <sjg:gridColumn name="codigo" index="codigo" title="Codigo" dataType="json" value="#concurso.codigo" />


</sjg:grid>

The grid doesn't load anything. But I can load data in a HTML table with .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遗弃M 2025-01-02 10:33:41

好吧,如果您可以看到 HTML 表中的数据,那么您的方法是正确的,但您仍然需要做更多的事情。

为了用数据填充 jquery-grid,该数据必须采用 JSON 格式,因此您必须做的第一件事是在 Struts2 Web 应用程序中启用 JSON 支持

尽管有很多指南,但我建议您其中一个进行深入研究与jquery网格。

但作为初学者,您可能会在向项目、依赖项等添加新的 jar 时遇到麻烦。因此,您能做的最好的事情就是从上述页面的下载部分下载代码示例(也此处)。在那里您会找到很多资源,但请选择示例

struts2-jquery-grid-showcase-3.5.1.war

并将此 .war 文件导入到您最喜欢的开发 IDE 中。您将看到它像一个魅力一样工作,具有所需的 jar 文件和依赖项(您可以将它们复制到您的项目中)。

希望这对您有帮助。

Well, if you can see the data in an HTML table, you are in the right way, but you still need to do something more.

In order to fill the jquery-grid with your data, that data must be in JSON format, so the first you must do is to enable JSON suppport in your Struts2 webapplication.

Although there are many guides, I advise you that one to go in depth with jquery-grid.

But as you are beginner, you'll maybe have troubles adding new jars to your project, dependencies, and so forth. So, the best you can do is download the code-example from the download section of the above page (also here). There you'll find a lot of resources, but choose for example

struts2-jquery-grid-showcase-3.5.1.war

and import this .war file into your favourite development IDE. You'll see it working like a charm, with needed jar files and dependencies (you can copy them to your project).

Hope this help you.

濫情▎り 2025-01-02 10:33:41
gridModel="lstUserBean"

这个 lstUserBean 应该是 UserBean 的列表,网格将显示其数据。该列表应该有 getter/setter,并且 sjg:grid 的 href 属性应该指向该操作,并且该操作应该返回 JSON 结果。单个 UserBean 对象将显示为单行数据,因此请确保所有属性名称与 sjg:gridColumn 的 name 属性匹配,并且这些属性在 UserBean 类中具有适当的 getter。

这里有更多示例。您会在那里找到许多网格以及项目源代码。

gridModel="lstUserBean"

This lstUserBean should be a list of UserBean, whose data the grid will show. This list should have getter/setter and the href attribute of sjg:grid should point to this action, and this action should return a JSON result.A single UserBean object will be shown as a single row of data, so make sure all attrribute names matches with the name attribute of sjg:gridColumn and those attributes have appropriate getters in UserBean class.

Here are a few more examples. You will find a number of grids there along with project source code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文