Struts returns json data of the object.

Source: Internet
Author: User

To return the json data of an object in struts


[Html]
<Action name = "getUserByName" class = "com. action. UserManagerAction" method = "getUserByName">
<Result name = "success" type = "json">
UserInfo
</Result>
</Action>

<Action name = "getUserByName" class = "com. action. UserManagerAction" method = "getUserByName">
<Result name = "success" type = "json">
UserInfo
</Result>
</Action>
The returned result is the json data of all member variables of the entire action class. To return the data of the userInfo object, you must define the return parameter as the root object.


[Html]
<Action name = "getUserByName" class = "com. action. UserManagerAction" method = "getUserByName">
<Result name = "success" type = "json">
<Param name = "root">
UserInfo
</Param>
</Result>
</Action>

<Action name = "getUserByName" class = "com. action. UserManagerAction" method = "getUserByName">
<Result name = "success" type = "json">
<Param name = "root">
UserInfo
</Param>
</Result>
</Action>
The following are definitions of returned json data.


[Html]
<! -- Encapsulate all methods starting with get -->
<Result type = "json" name = "user">
</Result>

<! -- Only include the user. id attribute -->
<Result type = "json" name = "user">
<Param name = "includeProperties">
User \. id
</Param>
</Result>

<! -- Return the user's JSON List, where userInfosList is a List type attribute in action, userInfosList \ [\ d + \] \. userName indicates that the object stored in userInfosList is 0 .. end's userName attribute (the objects stored in the list must have the userName attribute)
-->
<Result name = "success" type = "json">
<Param name = "includeProperties">
UserInfosList \ [\ d + \] \. userName, userInfosList \ [\ d + \] \. password
</Param>
</Result>

<! -- Does not contain the user attribute -->
<Result type = "json" name = "list">
<Param name = "excludeProperties">
User
</Param>
</Result>

<! -- The root object only contains user -->
<Result type = "json">
<Param name = "root">
User
</Param>
</Result>

<! -- The field (attribute) of the parent class in the "root" object will not (yes ?) JSON data is stored by default. If you do not want to do this, you must specify ignoreHierarchy as false during configuration: -->
<Result type = "json">
<Param name = "ignoreHierarchy"> false </param>
</Result>

<! -- Encapsulate all methods starting with get -->
<Result type = "json" name = "user">
</Result>
 
<! -- Only include the user. id attribute -->
<Result type = "json" name = "user">
<Param name = "includeProperties">
User \. id
</Param>
</Result>
 
<! -- Return the user's JSON List, where userInfosList is a List type attribute in action, userInfosList \ [\ d + \] \. userName indicates that the object stored in userInfosList is 0 .. end's userName attribute (the objects stored in the list must have the userName attribute)
-->
<Result name = "success" type = "json">
<Param name = "includeProperties">
UserInfosList \ [\ d + \] \. userName, userInfosList \ [\ d + \] \. password
</Param>
</Result>
 
<! -- Does not contain the user attribute -->
<Result type = "json" name = "list">
<Param name = "excludeProperties">
User
</Param>
</Result>
 
<! -- The root object only contains user -->
<Result type = "json">
<Param name = "root">
User
</Param>
</Result>
 
<! -- The field (attribute) of the parent class in the "root" object will not (yes ?) JSON data is stored by default. If you do not want to do this, you must specify ignoreHierarchy as false during configuration: -->
<Result type = "json">
<Param name = "ignoreHierarchy"> false </param>
</Result>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.