皓月白熏 2024-06-25 14:46 采纳率: 82.1%
浏览 5
已结题

mybatis,xml不生效的问题

mapper接口:

img


有问题的xml:

<!--到位-->
    <if test="condition.completed != null and (condition.completed = '0' or condition.completed='1')" >
      <choose>
        <when test="condition.completed = '0'">
          and a.vrfamount = a.totalamount
          and a.invoiceamount = a.totalamount
        </when>
        <otherwise>
          <![CDATA[ and (a.vrfamount <> a.totalamount or a.invoiceamount <> a.totalamount) ]]>
        </otherwise>
      </choose>
    </if>

前端传入:
"completed": "0"
还是传入:
"completed": "1"
都走的这个:
and a.vrfamount = a.totalamount
and a.invoiceamount = a.totalamount
修改了方式:

<if test="condition.completed != null">
      <if test="condition.completed == '0'">
        and a.vrfamount = a.totalamount and a.invoiceamount = a.totalamount
      </if>
      <if test="condition.completed == '1'">
        <![CDATA[
      and (a.vrfamount <> a.totalamount or a.invoiceamount <> a.totalamount)
    ]]>
      </if>
    </if>

前端传入:
"completed": "0"
还是传入:
"completed": "1"
哪个条件都不走。
请问为啥,我想要的是传入0走and a.vrfamount = a.totalamount and a.invoiceamount = a.totalamount
传入1走:and (a.vrfamount <> a.totalamount or a.invoiceamount <> a.totalamount)
啥也不传就啥也不走。哪里有问题呀?

  • 写回答

3条回答 默认 最新

  • 皓月白熏 2024-06-25 15:02
    关注

    我将数据类型改成了Integer,然后传入0或1就行。用String就不行,不知道啥原因

    <if test="condition.completed != null and condition.completed == 0">
          and a.vrfamount = a.totalamount
          and a.invoiceamount = a.totalamount
        </if>
        <if test="condition.completed != null and condition.completed == 1">
          and (a.vrfamount != a.totalamount or a.invoiceamount != a.totalamount)
        </if>
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 7月3日
  • 已采纳回答 6月25日
  • 创建了问题 6月25日

悬赏问题

  • ¥15 react-diff-viewer组件,如何解决数据量过大卡顿问题
  • ¥20 遥感植被物候指数空间分布图制作
  • ¥15 安装了xlrd库但是import不了…
  • ¥20 Github上传代码没有contribution和activity记录
  • ¥20 SNETCracker
  • ¥15 数学建模大赛交通流量控制
  • ¥15 为什么我安装了open3d但是在调用的时候没有报错但是什么都没有发生呢
  • ¥50 paddleocr最下面一行似乎无法识别
  • ¥15 求某类社交网络数据集
  • ¥15 靶向捕获探针方法/参考文献