script
在注解中使用动态 SQL 其实十分简单,只需在动态 SQL 语句的外面包上一层script标签即可。如下:
@Select({"<script>",
"SELECT * FROM imooc_user",
" WHERE",
" <choose>",
" <when test='id != null'>",
" id = #{id}",
" </when>",
" <when test='username != null'>",
" username = #{username}",
" </when>",
" <otherwise>",
" 1 = 0",
" </otherwise>",
" </choose>",
"</script>"})
User selectUserByIdOrName(@Param("id") Integer id, @Param("username") String username);