使用ssm編寫的一個(gè)功能輸入機(jī)器編號(hào),開始時(shí)間,結(jié)束時(shí)間,查找實(shí)現(xiàn)過(guò)程中,當(dāng)機(jī)器編號(hào)輸入一個(gè)不存在的值,或者開始時(shí)間空著,都會(huì)報(bào)錯(cuò),錯(cuò)誤顯示是sql語(yǔ)句錯(cuò)誤mybatis的xml文件中,sql語(yǔ)句如下:<select id="findByRowBounds" resultMap="BaseResultMap">?? ??? ?select?? ??? ?<include refid="Base_Column_List" />?? ??? ?from yujing_record?? ??? ?<where>?? ??? ??? ?<if test="macid != null? and macid !=''">?? ??? ??? ??? ?and macid like concat('%',#{macid},'%')?? ??? ??? ?</if>?? ??? ??? ?<if test="start != null and start !=''">?? ??? ??? ??? ?and time <![CDATA[>]]>?? ??? ??? ??? ?#{start}?? ??? ??? ?</if>?? ??? ??? ?<if test="end != null and end !=''">?? ??? ??? ??? ?and time <![CDATA[<]]>?? ??? ??? ??? ?#{end}?? ??? ??? ?</if>?? ??? ?</where>?? ??? ?order by time desc limit #{sindex},#{size}?? ?</select>
2 回答

Liu__
TA貢獻(xiàn)2條經(jīng)驗(yàn) 獲得超1個(gè)贊
按照?<if end != null and end !=“”>
?? ??? ??? ??? ?and time?? #{end}
?</if>
的話運(yùn)行報(bào)錯(cuò)

sunbohan00
TA貢獻(xiàn)44條經(jīng)驗(yàn) 獲得超73個(gè)贊
if判斷語(yǔ)句的問題,可能是我見得少吧,你這么寫的我確實(shí)沒見過(guò),
當(dāng)空值的時(shí)候,if判斷沒有生效,所以空值進(jìn)行搜索會(huì)報(bào)錯(cuò)。
試試這樣
?<if end != null and end !=“”>
?? ??? ??? ??? ?and time?? #{end}
?</if>
添加回答
舉報(bào)
0/150
提交
取消