在注解中使用动态 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);

相关文章:

  • 2022-12-23
  • 2021-10-01
  • 2021-06-01
  • 2021-11-05
  • 2022-12-23
  • 2022-01-08
  • 2022-01-02
  • 2021-06-10
猜你喜欢
  • 2021-07-02
  • 2022-12-23
  • 2021-12-11
  • 2021-10-18
  • 2022-01-12
相关资源
相似解决方案