Mybatis_ Personal Summary

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.