美文网首页
展示近10天的数据JAVA遇到的bug

展示近10天的数据JAVA遇到的bug

作者: 奋斗滴猩猩 | 来源:发表于2018-11-21 13:24 被阅读11次

    需求是展示近10天的数据

    // 修改后的代码
    String AAA_QUERY = "select u FROM AAAAA u where (to_days(now()) 
    - to_days(from_unixtime(u.mEndTime/1000,\'%Y-%m-%d\'))) <= 9";
    @Query(value = AAA_QUERY)
        Iterable<AAAAA> getData();
    
    // 注:AAA是引入该@table('tb名称')的类名
    // u是该table的别名
    

    遇到问题:
    1、antlr.NoViableAltException: unexpected token: )
    因为我输入的Sql语句少了 括号

    String AAA_QUERY = "select u FROM AAAAA u where 缺(   to_days(now()) 
    - to_days(from_unixtime(u.mEndTime/1000,\'%Y-%m-%d\'))   缺) <= 9";
    

    2、# [org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: * near line 1]

    String AAA_QUERY = "select * (应该修改为 u ,这是 table的别名) 
       FROM AAAAA u where (to_days(now()) - to_days(from_unixtime(u.mEndTime/1000,\'%Y-%m-%d\'))) <= 9";
    

    参考:https://stackoverflow.com/questions/40927513/querysyntaxexception-unexpected-token?rq=1
    3、Caused by: java.lang.IllegalArgumentException: org.hibernate.QueryException: unexpected char: '"' [s
    Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Unable to locate appropriate constructor on class

    // 该问题是因为,sql语句中 有",我改为'即可
    from_unixtime(u.mEndTime/1000,\'%Y-%m-%d\')
    

    4、Error creating bean with name 'AAAAAA': Unsatisfied dependency expressed through field 'BBBBBBB'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'BBBBBBB': Invocation of init method failed

    解决完上面sql语句的bug之后,该问题解决,
    

    相关文章

      网友评论

          本文标题:展示近10天的数据JAVA遇到的bug

          本文链接:https://www.haomeiwen.com/subject/qgvqqqtx.html