Automatic Object Assembler

Source: Internet
Author: User

Automatic Object Assembler

1. Some friends say that it is very troublesome to encapsulate data into objects. The favorite thing about hibernate is that it is easy to operate data. What I want to talk about is that the framework is an advanced encapsulation of basic operations. Just as data is encapsulated into objects and nothing is left blank, an automatic object assemble is simply implemented. You can study it. Of course, if you are interested, you can expand functions.

 

2. The Automatic Object assembler, as its name implies, is to let the program fill in the data to the object through simple configuration.

 

3. As many of you know, the procedure for querying an object is to get the database connection --> construct a query statement --> Get PreparedStatement --> get the ResultSet result set, the last step is to fill in the data to the object before you can operate the object.

 

4. General filling objects:

conn = DB.getConn();String sql = select * from teacher;rs = DB.executeQuery(conn, sql);while(rs.next()){Teacher t = new Teacher();t.setTno(rs.getString(tno));t.setDno(rs.getString(dno));t.setTname(rs.getString(tname));t.setProfess(rs.getString(profess));t.setDname(rs.getString(dname));t.setTel(rs.getString(tel));t.setTsex(rs.getString(tsex));t.setQq(rs.getString(qq));list.add(t);}

 

5. query statements are often used in projects, but it is okay to fill the object with a small amount of data. Once the data volume is too large, it is disgusting if it is not an error.

 

6. The Automatic Object assembler I wrote actually saves you the operation of this encapsulated object.

 

VII. Use Cases of object auto assemblier:

1. Create an AutoWise class (you can extract this class from the demo project I uploaded)

2. Use the following when an object needs to be assembled:

New AutoWise (). GetObject (com. almostman. base. Book, books, set );

3. You can use the above simple configuration.

 

8. Notes:

1. When creating AutoWise, We need to input the object type

2. The first parameter of the getObject () method is the Global Path of the object we created.

3. The second parameter of the getObject () method is the set of data assembly objects.

4. The third parameter of the getObject () method is the ResultSet result set obtained by the query.

 

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.