specification
The name of the XML map file is the same as the name of the Mapper interface, and the XML map file and the Mapper interface are placed under the same package (the same package and the same name).
The namespace attribute of the XML map file is the fully qualified name of the Mapper interface.
The id of the SQL statement in the XML mapping file is the same as the method name in the Mapper interface, and the return type is the same.
Usage
When the SQL statement is more complicated, you can choose the form of xml, but when the SQL statement is simple, you can directly write SQL using the annotations in mapper
Dynamic SQL tags
if
<if>: Used to determine whether the condition is true, use the test attribute to make the condition judgment. If the condition is true, then splice SQL
<where>: The where element will only insert the where clause if the child element has content, and will automatically remove and and or at the beginning of the clause.
<?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE mapper PUBLIC "-////DTD Mapper 3.0//EN" "/dtd/" > <mapper namespace=""> <select resultType=""> select * from user <where> <if test="name!=null"> name like concat('%',#{name},'%') </if> <if test="gender !=null"> and gender=#{gender} </if> </WHERE> </select> </mapper>
This is the end of this article about mybatis-xml mapping file and mybatis dynamic sql. For more related contents of mybatis-xml mapping file, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!