On the compilation specification of mapping XML header file

Time:2021-4-29

Here, we can refer to the official website of mybatis (mybatis. Org / mybatis-3 /) to query the XML header file writing specification, and directly copy and paste for reference.

The specific steps are as follows:

  1. According to mybatis. Mapper locations = classpath / mapper in resources / application. Properties//. XML configuration path for file creation.

On the compilation specification of mapping XML header file

  1. Create an XML file in the mapper.brand directory

On the compilation specification of mapping XML header file

  1. Query XML Mapping header file format through mybatis official (mybatis. Org / mybatis-3 /):
    On the compilation specification of mapping XML header file

On the compilation specification of mapping XML header file

On the compilation specification of mapping XML header file

Continue to find the mapping file format:
On the compilation specification of mapping XML header file
Confirm the required mapping file header specification and directly copy it to our own XML file for use
On the compilation specification of mapping XML header file

4. Configure the mapping body

  • The namespace should be consistent with the full class name of Dao

On the compilation specification of mapping XML header file

  • The resulttype should be consistent with the full name of the class in POJO:

On the compilation specification of mapping XML header file

  • The primary ID should be consistent with the method name in Dao package:

On the compilation specification of mapping XML header file

Summary:
Simple SQL statements can be described directly with annotations. Complex SQL is suggested to be written in the XML Mapping file, which makes the structure clearer and more flexible!

On the compilation specification of mapping XML header file

matters needing attention:
1. Check whether the configuration path of mybatis in resources / application.properties is consistent with the created XML Mapping file path;
2. Check whether the mapping file namespace is the same as the full class name of Dao interface (note the space)
3. Check whether the access method name has the corresponding element ID in the mapping file (pay attention to the space, case, etc.)
4. Check whether the resulttype or resultmap attribute is defined in the mapping element