Struts2 receives data associated with multiple tables

Source: Internet
Author: User
Today, when we make a billing move, we use the modeldriver of struts2 to receive the data submitted by the user, which is associated with the user Details table, telephone information table, package information table, and administrator information table; the submitted data includes phone numbers, user detailed addresses and personal information, package names, and package types ,,,
@ Entitypublic class user {private int ID; private string username; private string password; private string type; private string status; private int counter; private date radate; private customer customerid; // user details private phone phoneid; // phone information private pack packid; // package details private manager managerid; // which administrator has entered the private int currentphone; private int currentmassage; private int currentdata;

When the user model is used to receive data, it never receives data. After reading a lot of articles online, it still cannot find a solution. If properties are used to receive data, there are too many codes in the entire useraction controller to be directly looked.

Suddenly, I thought of using the data transmission object DTO class (Data Transport object) and some people call it pojo, no matter what it is called; it means to build a simple JavaBean, this is used to transmit data;

Create a useradddto class for the user, write the required data attributes (Note: The property names and attribute types must be consistent), and generate the setter/getter method.

Public class useradddto {private string username; private string password; private string type; private string realname; private string mobilephone; private string packname; private string status; private string customerid; // <span style = "color: # ff0000;"> do not use the int type. Otherwise, data cannot be received. </span> private string counter; private string phoneid; private string packid; private string managerid;


Finally, a new object in useraction is generated and the setter/getter method is generated.

private UserAddDTO addDTO  = new UserAddDTO();
public UserAddDTO getAddDTO() {return addDTO;}public void setAddDTO(UserAddDTO addDTO) {this.addDTO = addDTO;}

Once again, you can accept the data submitted from multiple tables !!! Try it !!


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.