Giving an empty json result while executing struts 2 action class

后端 未结 1 1489
闹比i
闹比i 2021-01-16 05:53

Im trying to retrieve data from DB using hibernate ORM and get the out-put as json result using Struts2. Everything work up to retrieving data from DB, but for the json res

1条回答
  •  野的像风
    2021-01-16 06:53

    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"})
    })
    

    0 讨论(0)
提交回复
热议问题