MyBatis:check the manual that corresponds to your MySQL server version

昨天用java的SpringBoot写项目,底下是个查询语句(为了说明方便,使用*):

        select 
           *    
        from t_student
        where birthday    > = #{beforeDate} and birthday   <= #{nowDate}
        order by id
        /*       beforeDate是当前日期的前七天      */

报错:

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 '= '2018-11-14 09:42:22.383' and sign_time  <= '2018-11-07 09:42:22.383' ' at line 15

报错信息是:在SQL语法中有一个错误;请检查对应于MySQL服务器版本的正确语法使用的手册。






检查了一下,表名、字段名等都没有问题,框架也正常。
我一开始以为是jdbcType的问题,就加上了jdbcType

        select 
           *    
        from t_student
        where birthday    &gt; = #{beforeDate,jdbcType=TIMESTAMP} and birthday   &lt;= #{nowDate,jdbcType=TIMESTAMP}
        order by id
        /*       beforeDate是当前日期的前七天      */

仍然报错。。。。。





揪了N多头发以后,终于发现,是>和=之间有个空格。。。。把空格删了就好了。

        select 
           *    
        from t_student
        where birthday    &gt;= #{beforeDate,jdbcType=TIMESTAMP} and birthday   &lt;= #{nowDate,jdbcType=TIMESTAMP}
        order by id
        /*       beforeDate是当前日期的前七天      */
发布了48 篇原创文章 · 获赞 36 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/weixin_42845682/article/details/84061426