Struts2 JSON 插件与 Hibernate

发布于 2024-10-21 12:55:44 字数 1245 浏览 1 评论 0原文

所以我尝试从 AcaClasses 列表创建一个 JSON 对象。

操作类:

public class StudentJSONAction extends ActionSupport{

    //Your result List
    private List<AcaClass> gridModel;


    public String getJSON() {
        return execute();
    }

    public String execute() {

        //Get the first student from the Factory and get their AcaClasses
        gridModel = StudentFactory.getAll().get(0).getAcaClasses();

        return SUCCESS;
    }


       //Getters and Setters

StudentFactory 是我与 hibernate 数据库的接口。

Struts.xml

<action name="getJSON" class="StudentJSONAction">
<result type="json">
        <param name="enableSMD">true</param>
        <param name="ignoreInterfaces">false</param>
</result>
</action>

当我调用 getJSON 操作时,我得到的只是:

{"methods":[],"objectName":null,"serviceType":"JSON-RPC","serviceUrl":"\/FlowridersSP\/getJSON","version":".1"}

This 问题与我的非常相似,但我想看看是否有使用 Struts2 JSON 插件的解决方案

问题:为什么我没有得到 JSON 形式的 AcaClasses 列表?

我的最终目标是将此 JSON 插入 JQuery 网格插件中

So I'm trying to create a JSON object from a List of AcaClasses.

Action Class:

public class StudentJSONAction extends ActionSupport{

    //Your result List
    private List<AcaClass> gridModel;


    public String getJSON() {
        return execute();
    }

    public String execute() {

        //Get the first student from the Factory and get their AcaClasses
        gridModel = StudentFactory.getAll().get(0).getAcaClasses();

        return SUCCESS;
    }


       //Getters and Setters

The StudentFactory is my interface to the hibernate database.

Struts.xml

<action name="getJSON" class="StudentJSONAction">
<result type="json">
        <param name="enableSMD">true</param>
        <param name="ignoreInterfaces">false</param>
</result>
</action>

When I call the getJSON action, all I get is:

{"methods":[],"objectName":null,"serviceType":"JSON-RPC","serviceUrl":"\/FlowridersSP\/getJSON","version":".1"}

This problem is very similar to mine but I would like to see if there is a solution using the Struts2 JSON Plugin

Question: Why am I not getting back a list of AcaClasses in JSON form?

My end goal is to plug in this JSON in the JQuery Grid Plugin

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

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

发布评论

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

评论(1

玩套路吗 2024-10-28 12:55:44

我不熟悉 JSON 插件,但是您是否正确配置插件来序列化 gridModel ?快速浏览一下插件文档表明您可能还需要设置 root 参数:此外

<action name="getJSON" class="StudentJSONAction">
  <result type="json">
    <param name="enableSMD">true</param>
    <param name="ignoreInterfaces">false</param>
    <param name="root">gridModel</param>
  </result>
</action>

,尝试确定问题是与 StudentFactory 还是与 JSON 序列化有关。您可以使用虚拟 AcaClass 对象列表设置 gridModel 并查看序列化是否正常工作。此外,正如 @Quaternion 所建议的,您可以记录由 StudentFactory 加载的 AcaClass 对象列表,并验证它是否正在加载预期的实例。

I am not familiar with JSON plugin, but are you correctly configuring the plugin to serialize the gridModel? A quick look at the plugin documentation suggests that you might want to set the root parameter also:

<action name="getJSON" class="StudentJSONAction">
  <result type="json">
    <param name="enableSMD">true</param>
    <param name="ignoreInterfaces">false</param>
    <param name="root">gridModel</param>
  </result>
</action>

Also, try to identify if the problem is with StudentFactory or with the JSON serialization. You can set up gridModel with a list of dummy AcaClass objects and see if the serialization works correctly. Also, as suggested by @Quaternion, you can log the list of AcaClass objects loaded by StudentFactory and verify that it is loading the expected instances.

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