为了账号安全,请及时绑定邮箱和手机立即绑定

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 关注
  • 3317 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信