Mybatis if test中字符串比较

古城微笑少年丶 2022-08-12 07:28 336阅读 0赞

在传入参数的map中判断某个参数是否为某个字符串

这里的字符串比较

  1. <if test='Where_Pattern == "NONE"'>
  2. <foreach collection="key_value" index="index" item="item" separator=" or " open=" where (" close=") " >
  3. ${index} #{item}
  4. </foreach>
  5. </if>

Where_Pattern是map中的key,判断它的值用以上的方式就可以。

使用的原文如下:

-——————————————

  1. <select id="getEntityForList_QueryHelp" parameterType="map" resultMap="UserMap">
  2. select <include refid="sql"/> from ${tableName}
  3. <if test='Where_Pattern == "AND"'>
  4. <foreach collection="key_value" index="index" item="item" separator=" and " open=" where (" close=") " >
  5. ${index} #{item}
  6. </foreach>
  7. </if>
  8. <if test='Where_Pattern == "OR"'>
  9. <foreach collection="key_value" index="index" item="item" separator=" or " open=" where (" close=") " >
  10. ${index} #{item}
  11. </foreach>
  12. </if>
  13. <if test='Where_Pattern == "NONE"'>
  14. <foreach collection="key_value" index="index" item="item" separator=" or " open=" where (" close=") " >
  15. ${index} #{item}
  16. </foreach>
  17. </if>
  18. <if test="_parameter.containsKey('like')">
  19. ${like}
  20. </if>
  21. <if test="_parameter.containsKey('group_by')">
  22. ${group_by}
  23. </if>
  24. <if test="_parameter.containsKey('order_by')">
  25. ${order_by}
  26. </if>
  27. <if test="_parameter.containsKey('limit')">
  28. limit ${pageNum},${pageSize}
  29. </if>
  30. </select>

发表评论

表情:
评论列表 (有 0 条评论,336人围观)

还没有评论,来说两句吧...

相关阅读