1. [Mandatory] Specific column names should be specified during query, rather than using *.
Note:
1) * increases parsing cost.
2) It may introduce mismatch with resultMap when adding or removing query columns.
2. [Mandatory] Name of Boolean property of POJO classes cannot be prefixed with is, while DB column name should prefix with is. A mapping between properties and columns is required.
Note: Refer to rules of POJO class and DB column definition, mapping is needed in resultMap. Code generated by MyBatis Generator might need to be adjusted.
3. [Mandatory] Do not use resultClass as return parameters, even if all class property names are the same as DB columns, corresponding DO definition is needed.
Note:
Mapping configuration is needed, to decouple DO definition and table columns, which in turn facilitates maintenance.
4. [Mandatory] Be cautious with parameters in xml configuration. Do not use ${}
in place of #{}
, #param#
. SQL injection may happen in this way.
5. [Mandatory] iBatis built in queryForList(String statementName, int start, int size) is not recommended.
Note: It may lead to OOM issue because its implementation is to retrieve all DB records of statementName’s corresponding SQL statement, then start, size subset is applied through subList.
Positive example: Use #start#, #size# in sqlmap.xml.
Map<String, Object> map = new HashMap<String, Object>();
map.put("start", start);
map.put("size", size);
6. [Mandatory] Do not use HashMap or HashTable as DB query result type.
7. [Mandatory] gmt_modified column should be updated with current timestamp simultaneously with DB record update.
8. [Recommended] Do not define a universal table updating interface, which accepts POJO as input parameter, and always update table set c1=value1, c2=value2, c3=value3, … regardless of intended columns to be updated. It is better not to update unrelated columns, because it is error prone, not efficient, and increases binlog storage.
9. [For Reference] Do not overuse @Transactional. Because transaction affects QPS of DB, and relevant rollbacks may need be considered, including cache rollback, search engine rollback, message making up, statistics adjustment, etc.
10. [For Reference] compareValue of \