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:
- According to mybatis. Mapper locations = classpath / mapper in resources / application. Properties//. XML configuration path for file creation.
- Create an XML file in the mapper.brand directory
- Query XML Mapping header file format through mybatis official (mybatis. Org / mybatis-3 /):
Continue to find the mapping file format:
Confirm the required mapping file header specification and directly copy it to our own XML file for use
4. Configure the mapping body
- The namespace should be consistent with the full class name of Dao
- The resulttype should be consistent with the full name of the class in POJO:
- The primary ID should be consistent with the method name in Dao package:
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!
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