Object Relational Mapping (ORM) is a programming technique that converts data between different types of systems by using object-oriented programming languages. In effect, ORM creates a “virtual object database” that can be used in programming languages.
Do not use resultClass as the return parameter. Define the class attribute name even if all class attribute names are in one-to-one correspondence with database fields, and define a class attribute name for each table.
Note
Configure mapping relationships to decouple fields from the DO class for ease of maintenance.
Pay attention to the following parameter configuration method in the
sql.xmlfile: Do not use${}in#{}or#param#, which may cause SQL injection.Do not use
queryForList(String statementName,int start,int size)that comes with iBATIS.Note
This method obtains all records of the SQL statements with the corresponding statementName from the database, and obtains the start and size subsets through subList. This method has caused an out-of-memory (OOM) issue in the online system. To solve this problem, you can introduce
#start#and#size#into sqlmap.xml. For example:Mapmap = newHashMap (); map.put("start", start); map.put("size", size); Do not directly use HashMap or HashTable as the output of a query result set.
Here is a counter-example: To avoid writing a
<resultMap>entry, a developer uses HashTable to receive results returned by the database. Generally, bigint values in the result are converted to Long values. However, due to database version differences in an online system, bigint values were converted into BigInteger values, causing a production issue.Update the
gmt_modifiedfield value of the record to the current time when you update records in the data table.Avoid creating a large and comprehensive data update API that takes the POJO class as input. It is not advisable to run a generic
update table set c1=value1,c2=value2,c3=value3;statement without considering the specific fields to be updated. When executing an SQL statement, avoid updating fields that is not modified. Updating unmodified fields can lead to errors, hinder efficiency, and increase the storage size of binlogs.