Giving an empty json result while executing struts 2 action class

穿精又带淫゛_ 提交于 2019-12-01 11:58:20
Andrea Ligios

Struts2 JSON plugin will serialize your whole action, including all the (non-transient) properties with a getter.

Since you are hiding your variables (definitely not a best practice, especially because it forces you to manually write every getter and setter... brr), and you have different names for the variable and for the getter, you are pointing the variable, but you should point the getter (then currency instead of _currency):

@Action(value = "currencies", results = {
    @Result(name = "success", 
            type = "json", 
          params = {"includeProperties","currency\\[\\d+\\]\\..*"})
})

Also note that you can specify a root object, that is often preferred to the includeProperties technique, as described here:

@Action(value = "currencies", results = {
    @Result(name = "success", 
            type = "json", 
          params = {"root","currency"})
})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!