In the process of developing the data access layer using the MyBatis framework, I encountered a lot of detail during this time to trap my development progress, although they are very humble, but once you ignore their existence, it may make you very painful, here I would like to share the pit I met.
First, the MyBatis Dynamic Agent Mode Development specification:
1. Note that the value of the Namespace property in the MyBatis mapping configuration file must be the full path name of the Mapper interface.
2. Note that the value of the ID on the label in the mapping file must be consistent with the method name in the Mapper interface.
3. Requires that the data type of the parameters passed in the mapping file must be consistent with the data type of the parameter on the method in the Mapper interface.
4. Requires that the data type of the output parameter in the mapping file be consistent with the data type of the method's return value in the Mapper interface.
Second, use the MyBatis mapping file #{}, ${} Two symbols of the attention point:
1, #{}, represents a placeholder, plays a role in the placeholder.
If the data type of the input parameter in the mapping file is a data type of a simple type (String, double, Integer, Boolean, and so on), then the variable name in the placeholder is random.
If the data type of the input type in the mapping file is of type Pojo, then the variable name in the placeholder must be the property name of the Pojo object, and if the property in the Pojo object contains other objects, the variable name must be a property. property. Properties ...
2, ${}, indicating the concatenation of characters , play the role of concatenation of strings.
If the data type of the input parameter in the mapping file is a data type of a simple type (String, Double, Integer, Boolean, and so on) , then the variable name in the concatenation character must be value.
If the data type of the input type in the mapping file is of type Pojo, then the variable name in the placeholder must be the property name of the Pojo object, and if the property in the Pojo object contains other objects, the variable name must be a property. property. Properties ...
3, in the development if the use of the splicing character ${} , it is important to note that the symbol has the risk of SQL injection , you must avoid the problem, can replace the substitution.
1 <if test= "Custname!=null and custname!=" >2 <!--"NOTE: Use the #{} placeholder as much as possible, is to prevent SQL injection problems "--3 <!--and cust_name like '%${custname}% '--4and cust_name like "%" #{custname} "%"5 </if>
Mybatis_ Personal Summary