BeanListHandler use precautions

BeanListHandler use precautions

QueryRunner is a commonly used tool for receiving database usage, which can greatly improve the convenience of database processing.

Mainly to talk about some precautions for the use of query in QueryRunner.
The most commonly used is BeanListHandler: each row of data in the result set is encapsulated into a corresponding JavaBean instance and stored in the List.

用法:qr.query(sql, new BeanListHandler(T.class));

It should be noted that the attribute name of the corresponding JavaBean object should be the same as the return value field name after the database query (not case sensitive), and the corresponding JavaBean must have a parameterless construction method *, because the BeanListHandler corresponds to The set method of each field in JavaBean corresponds to. If you only have a parameter construction method, you cannot create an object through the parameterless construction method and then call the corresponding set method to assign values ​​to the corresponding properties, resulting in an exception error.

Guess you like

Origin blog.csdn.net/interestANd/article/details/110525834