m0_58866636 2022-08-17 16:09 采纳率: 50%
浏览 72
已结题

关于#mybatis#的if标签

问题遇到的现象和发生背景

mybatis 增加一个if标签时就查询不到结果

增加type字段的if标签时
<select id="findInOutListByPage" resultType="com.ntvu.entity.InOut">
    select tio.*, tg.`goodName` as goodName
    from t_in_out tio
    inner join t_good tg on tg.`id` = tio.`goodId`
    <where>
        <if test="goodName != null and goodName != ''">
            and tg.goodName like concat('%',#{goodName},'%')
        </if>
        <if test="employeeName != null and employeeName != ''">
            and tio.employeeName like concat('%',#{employeeName},'%')
        </if>
        <if test="startDate!=null">
            <![CDATA[and tio.time>=#{startDate}]]>
        </if>
        <if test="endDate!=null">
            
            <![CDATA[and tio.time<=#{endDate}]]>
        </if>
        <if test="type != null">
            and tio.type = #{type}
        </if>
    </where>
    order by tio.id = #{id}
</select>
运行结果

img

把type字段的if标签注释掉就可以查到结果了

img

我想要达到的结果

为什么会这样

  • 写回答

10条回答 默认 最新

  • 阳光下下 2022-08-17 17:24
    关注
    order by tio.id = #{id} 排序为啥要这样写呢,还要传参数?
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(9条)

报告相同问题?

问题事件

  • 系统已结题 3月30日
  • 已采纳回答 3月22日
  • 创建了问题 8月17日