在 MyBatis 中,`include` 标签用于复用 SQL 片段。以下是其常见的写法: ```xml <!-- 定义可复用的 SQL 片段 --> <sql id="columnList"> id, name, age </sql> <!-- 在其他查询语句中引用该片段 --> <select id="selectUser" resultType="User"> select <include refid="columnList"/> from users where id = #{id} </select> ``` 在上述示例中,首先定义了一个名为 `columnList` 的 SQL 片段,然后在 `selectUser` 查询语句中通过 `<include refid="columnList"/>` 来引用该片段。 这样可以提高 SQL 语句的可维护性和复用性。 [2024-11-08 10:36:41 | AI写代码神器 | 173点数解答]