首先說我的場景:我是在前臺用layui框架的時間選擇器,取到兩個時間,開始時間和結(jié)束時間,在后臺我把取到的兩個日期2019-03-29 - 2019-03-31截取了出來,取成了兩個字符分別是:2019-03-29,2019-03-31,然后轉(zhuǎn)換成了Date,下面的代碼圖中能看到我轉(zhuǎn)換之后的值是什么樣子!然后報了一個莫名其妙的錯誤,很難受!是在是不知道哪里錯了,求大神指教,看下圖;這是后臺接收到值轉(zhuǎn)換并存入數(shù)據(jù)庫的實現(xiàn)下面是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
這種報錯實在是太詭異了!完全不知其所以然!求大神告知,重謝?。。。。。。。。。。?!
3 回答

慕標(biāo)琳琳
TA貢獻1830條經(jīng)驗 獲得超9個贊
<if test="startDate != null "> AND createdate >= #{startDate,jdbcType=DATE} </if> <if test="endDate != null "> AND createdate <= #{endDate,jdbcType=DATE} </if>
或者
<if test="startDate != null "> AND <![CDATA[ createdate >= #{startDate,jdbcType=DATE} ]]> </if> <if test="endDate != null "> AND <![CDATA[ createdate <= #{endDate,jdbcType=DATE} ]]> </if>
添加回答
舉報
0/150
提交
取消