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.