Struts2 JSON 插件与 Hibernate
所以我尝试从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不熟悉 JSON 插件,但是您是否正确配置插件来序列化
gridModel
?快速浏览一下插件文档表明您可能还需要设置root
参数:此外,尝试确定问题是与
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 theroot
parameter also:Also, try to identify if the problem is with
StudentFactory
or with the JSON serialization. You can set upgridModel
with a list of dummyAcaClass
objects and see if the serialization works correctly. Also, as suggested by @Quaternion, you can log the list ofAcaClass
objects loaded byStudentFactory
and verify that it is loading the expected instances.