MyBatis 3手册 MyBatis 3 动态SQL-script

2024-02-25 开发教程 MyBatis 3手册 匿名 6

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);