# This mybatis tag Full analysis: Analyze the role and usage of each label in mybatis one by one, you need to specify the code for example
SQL statement tag
<select id="getUserById" resultType="User"> SELECT * FROM users WHERE id = #{id} </select>
<insert id="insertUser" parameterType="User"> INSERT INTO users (id, name, age) VALUES (#{id}, #{name}, #{age}) </insert>
<update id="updateUser" parameterType="User"> UPDATE users SET name = #{name}, age = #{age} WHERE id = #{id} </update>
<delete id="deleteUser" parameterType="int"> DELETE FROM users WHERE id = #{id} </delete>
Parameter transfer tag
<parameterMap id="userMap" type="User"> <parameter property="id" jdbcType="INTEGER"/> <parameter property="name" jdbcType="VARCHAR"/> <parameter property="age" jdbcType="INTEGER"/> </parameterMap>
<select id="getUserById" resultType="User"> SELECT * FROM users WHERE id = #{id} </select>
Result set mapping tag
<resultMap id="userResultMap" type="User"> <id property="id" column="id"/> <result property="name" column="name"/> <result property="age" column="age"/> </resultMap>
<resultMap id="userResultMap" type="User"> <result property="id" column="id"/> </resultMap>
Dynamic SQL tag
<select id="getUserByName" resultType="User"> SELECT * FROM users <where> <if test="name != null"> AND name = #{name} </if> <if test="age != null"> AND age = #{age} </if> </where> </select>
<select id="getUserByCondition" resultType="User"> SELECT * FROM users <where> <choose> <when test="name != null"> AND name = #{name} </when> <when test="age != null"> AND age = #{age} </when> <otherwise> AND gender = #{gender} </otherwise> </choose> </where> </select>
The above is the detailed content of Comprehensive analysis of MyBatis tags: analyze the role and usage of each tag in MyBatis one by one. For more information, please follow other related articles on the PHP Chinese website!