亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

SSM 范圍查找以及分頁

SSM 范圍查找以及分頁

Liu__ 2018-07-17 17:37:38
使用ssm編寫的一個功能輸入機器編號,開始時間,結束時間,查找實現過程中,當機器編號輸入一個不存在的值,或者開始時間空著,都會報錯,錯誤顯示是sql語句錯誤mybatis的xml文件中,sql語句如下:<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貢獻2條經驗 獲得超1個贊


按照?<if end != null and end !=“”>
?? ??? ??? ??? ?and time?? #{end}
?</if>

的話運行報錯

查看完整回答
反對 回復 2018-07-17
?
sunbohan00

TA貢獻44條經驗 獲得超73個贊

if判斷語句的問題,可能是我見得少吧,你這么寫的我確實沒見過,

當空值的時候,if判斷沒有生效,所以空值進行搜索會報錯。

試試這樣

?<if end != null and end !=“”>
?? ??? ??? ??? ?and time?? #{end}
?</if>

查看完整回答
反對 回復 2018-07-17
  • Liu__
    Liu__
    我們查的條件有三個,一個macid,還有兩個時間,比如這個 <if test="macid != null and macid !=''"> and macid like concat('%',#{macid},'%') </if> 當macid為空的時候,我們希望就查出所有的macid,所以if里面的條件就不拼接 報的錯誤如下 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-10,10' at line 16
  • 2 回答
  • 0 關注
  • 3410 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號