阅读(3592) (0)

MyBatis 3 动态SQL-script

2022-04-11 10:16:33 更新

script

要在带注解的映射器接口类中使用动态 SQL,可以使用 ​script ​元素。比如:

    @Update({"<script>",
      "update Author",
      "  <set>",
      "    <if test='username != null'>username=#{username},</if>",
      "    <if test='password != null'>password=#{password},</if>",
      "    <if test='email != null'>email=#{email},</if>",
      "    <if test='bio != null'>bio=#{bio}</if>",
      "  </set>",
      "where id=#{id}",
      "</script>"})
    void updateAuthorValues(Author author);