且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何MyBatis中使用动态SQL查询与注释(如何使用selectProvider)?

更新时间:2022-01-12 18:24:45

你的替代解决方案。

您可以添加<脚本> 在你@annotation年初

you can add <script> at the beginning of your @annotation

@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>""")

在额外的,我们编译.groovy作为在我们的项目中的.class,因此,我们可以写SQL在@annotation像上面

In additional, we compile .groovy to .class in our projects, thus, we can write SQL in @annotation like above