ORM specification


1. [Mandatory] In table queries, never use * as the field list of the query. Which fields are required must be clearly stated.

Description: 1) Increase the query analyzer parsing cost. 2) Adding or subtracting fields is likely to be inconsistent with the resultMap configuration.


2. [Mandatory] The boolean attribute of the POJO class cannot be added with is, and the database field must be added with is _. It is required to conduct the connection between fields and attributes in the resultMap of mapping.

Note: See the definition of POJO class and database field definition. It is necessary to add mapping in sql.xml.


3. [Mandatory] Do not use resultClass as the return parameter. Even if all class attribute names correspond to database fields one-to-one, they still need to be defined; conversely, Every table must have a corresponding one.

Description: Configure the mapping relationship to decouple the fields from the DO class for easy maintenance.


4. [Mandatory] Note the use of parameters in xml configuration: #{}, # param # Do not use ${}. This method is prone to SQL injection .


5. [Mandatory] The queryForList(String statementName, int start, int size) that comes with iBATIS is not recommended use.

Explanation: The implementation method is to obtain all the records of the SQL statement corresponding to statementName in the database, and then obtain the subsets of start and size through subList, online OOM has occurred for this reason.

Positive example: Introduce #start#, #size

#
Map<String, Object> map = new HashMap<String, Object>();
map.put("start", start);
map.put("size", size);


6. 【 Mandatory] It is not allowed to directly use HashMap and Hashtable as the output of the query result set.


#7. [Mandatory] When updating the data table record, you must also update the corresponding gmt_modified field value of the record to the current time.


8. [Recommendation] Do not write a large and comprehensive data update interface. Pass it in as a POJO class, regardless of whether it is your own target update segment. All update table set c1=value1,c2=value2,c3=value3; This is wrong. When executing SQL, try not to update unmodified fields. First, it is error-prone; second, it is inefficient; third, binlog increases storage.


9. [Reference] @ Transactional Don’t abuse transactions. Transactions will affect the QPS of the database. In addition, where transactions are used, various rollback solutions must be considered, including cache rollback, search engine rollback, message compensation, statistical correction, etc.


10. [Reference] The compareValue in < isEqual > is a constant compared with the attribute value, usually a number, which means is accompanied by this condition when it means they are equal; < isNotEmpty > means it is not empty and not Execute when it is null; < isNotNull > means it will be executed when it is not null value

.