mybatis-plus 标签使用示例
时间: 2023-07-30 20:10:36 浏览: 116
mybatis-plus是MyBatis的增强工具,在标签使用上与MyBatis相似。以下是mybatis-plus中常用标签的使用示例:
1. insert标签
```xml
<insert id="insertUser" parameterType="User">
INSERT INTO user(name, age, email) VALUES(#{name}, #{age}, #{email})
</insert>
```
2. update标签
```xml
<update id="updateUserById" parameterType="User">
UPDATE user SET name=#{name}, age=#{age}, email=#{email} WHERE id=#{id}
</update>
```
3. delete标签
```xml
<delete id="deleteUserById" parameterType="Long">
DELETE FROM user WHERE id=#{id}
</delete>
```
4. select标签
```xml
<select id="getUserById" parameterType="Long" resultType="User">
SELECT id, name, age, email FROM user WHERE id=#{id}
</select>
```
5. resultMap标签
```xml
<resultMap id="userMap" type="User">
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="age" column="age"/>
<result property="email" column="email"/>
</resultMap>
```
6. association标签
```xml
<resultMap id="userMapWithDepartment" type="User">
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="age" column="age"/>
<result property="email" column="email"/>
<association property="department" javaType="Department" column="department_id" select="getDepartmentById"/>
</resultMap>
<select id="getUserWithDepartmentById" parameterType="Long" resultMap="userMapWithDepartment">
SELECT u.id, u.name, u.age, u.email, u.department_id FROM user u LEFT JOIN department d ON u.department_id=d.id WHERE u.id=#{id}
</select>
<select id="getDepartmentById" parameterType="Long" resultType="Department">
SELECT id, name FROM department WHERE id=#{id}
</select>
```
以上是mybatis-plus标签的使用示例,希望对你有所帮助。
阅读全文