springboot 使用druid往后台传值SQL报错,是在是头疼不知道怎么办了

首先说我的场景:我是在前台用layui框架的时间选择器,取到两个时间,开始时间和结束时间,在后台我把取到的两个日期2019-03-29 - 2019-03-31截取了出来,取成了两个字符分别是:2019-03-29,2019-03-31,然后转换成了Date,下面的代码图中能看到我转换之后的值是什么样子!然后报了一个莫名其妙的错误,很难受!是在是不知道哪里错了,求大神指教,看下图;

这是后台接收到值转换并存入数据库的实现

图片说明

下面是mapper.xml中语句

<!-- 模糊查询-->
 <select id="fuzzySelectLogs" resultType="OaLog">
        SELECT * FROM oa_log WHERE
        <if test="name != null">
            name LIKE CONCAT('%',#{name},'%')
        </if>
        <if test="startDate != null and endDate != null">
               AND createdate <![CDATA[>=]]> #{startDate} AND createdate <![CDATA[<]]> #{endDate}
        </if>
        ORDER BY createdate DESC
        <if test="limit!=null and page!=null">
            LIMIT #{limit} OFFSET #{page}
        </if>
    </select>

        <!-- 分页 -->
    <select id="fuzzySelectLogsCount" resultType="int">
        SELECT COUNT(*)FROM oa_log WHERE
        <if test="name != null">
            name LIKE CONCAT('%',#{name},'%')
        </if>
        <if test="startDate != null">
            AND createdate <![CDATA[>=]]> #{startDate} AND createdate <![CDATA[<=]]> #{endDate}
        </if>
    </select>

然后下面是报错!

2019-03-31 05:04:56.652 DEBUG 1675 --- [nio-8081-exec-3] c.h.oasys.dao.IOaLogDao.fuzzySelectLogs  : ==> Parameters:
 (String), 2019-03-29 00:00:00.0(Timestamp), 2019-03-31 00:00:00.0(Timestamp), 10(Integer), 0(Integer)
2019-03-31 05:04:56,687 ERROR Statement:152 - {conn-10005, pstmt-20013} execute error. SELECT * FROM oa_log WHERE

            name LIKE CONCAT('%',?,'%')


               AND createdate  >=  ? AND createdate  <  ?

        ORDER BY createdate DESC

            LIMIT ? OFFSET ?
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 '   AND createdate  >=  '2019-03-29 00:00:00' AND createdate 
 <  '2019-03-31 00' at line 6

这种报错实在是太诡异了!完全不知其所以然!求大神告知,重谢!!!!!!!!!!!!
慕哥6287543
浏览 2076回答 3
3回答

慕标琳琳

<if&nbsp;test="startDate&nbsp;!=&nbsp;null&nbsp;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AND&nbsp;createdate&nbsp;&nbsp;&gt;=&nbsp;#{startDate,jdbcType=DATE}&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;</if> &nbsp;&nbsp;&nbsp;&nbsp;<if&nbsp;test="endDate&nbsp;!=&nbsp;null&nbsp;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AND&nbsp;createdate&nbsp;&nbsp;&lt;=&nbsp;#{endDate,jdbcType=DATE}&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;</if>或者<if&nbsp;test="startDate&nbsp;!=&nbsp;null&nbsp;"> &nbsp;&nbsp;&nbsp;&nbsp;AND&nbsp;<![CDATA[&nbsp;createdate&nbsp;>=&nbsp;#{startDate,jdbcType=DATE}&nbsp;&nbsp;]]> </if> <if&nbsp;test="endDate&nbsp;!=&nbsp;null&nbsp;"> &nbsp;&nbsp;&nbsp;&nbsp;AND&nbsp;<![CDATA[&nbsp;createdate&nbsp;<=&nbsp;#{endDate,jdbcType=DATE}&nbsp;&nbsp;]]> </if>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java