mybatis-plus中可以使用<include>标签嘛
时间: 2023-12-12 20:01:55 浏览: 140
是的,Mybatis-Plus中可以使用`<include>`标签,它可以将SQL语句中的重复部分提取出来,减少代码重复,提高可维护性。使用`<include>`标签的语法格式如下:
```
<select id="selectUsers" resultMap="userResult">
SELECT
id, username, password, email, nickname, reg_time
FROM
user
<where>
<if test="username != null and username != ''">
and username like concat('%', #{username}, '%')
</if>
<if test="email != null and email != ''">
and email like concat('%', #{email}, '%')
</if>
</where>
<include refid="orderByClause"/>
LIMIT #{offset}, #{limit}
</select>
<sql id="orderByClause">
<if test="orderBy != null and orderBy != ''">
ORDER BY ${orderBy}
</if>
<if test="orderBy == null or orderBy == ''">
ORDER BY reg_time DESC
</if>
</sql>
```
在上面的例子中,`<include>`标签引用了`<sql>`标签中的`orderByClause`,简化了SQL语句的编写。
阅读全文