今天要做在查询条件scenecode为空的情况下返回所有数据,以下时在scenecode不为空的情况下的部分代码,请问该需要怎么加或者怎么改?

今天要做在查询条件scenecode为空的情况下返回所有数据,以下时在scenecode不为空的情况下的部分代码,请问该需要怎么加或者怎么改?

SELECT * from scene
        <where>
            and status = 1
            <if test="sceneCode != null and sceneCode != ''">
                and sceneCode = #{sceneCode}
            </if>
            <if test="sceneId != null and sceneId != ''">
                and id = #{sceneId}
            </if>
        </where>
SELECT * from scene
        <where>
            <if test="sceneCode != null and sceneCode != ''">
                sceneCode = #{sceneCode}
            </if>
        </where>

如果只要求传递的scenecode为空或是为null的情况下返回所有数据.按照上面可以解决问题.
如有帮助,欢迎采纳!