zoukankan      html  css  js  c++  java
  • jpa中时间戳格式应该用哪种类型

    遇到个bug,数据库时间存储用了datetime,但是下面的java jpa代码,查询回来,却只有日期。

            String innerSql = getInnerQuery(departmentId, keyword, type, startDate, endDate);
    
            SQLQuery query = manager.createNativeQuery(innerSql).unwrap(SQLQuery.class);
            if (PublicUtils.isNotEmpty(departmentId)) {
                query.setParameter("departmentId", departmentId);
            }
            if (StringUtils.isNotEmpty(type)) {
                query.setParameter("typeParam", Integer.valueOf(type));
            }
            if (StringUtils.isNotEmpty(keyword)) {
                query.setParameter("keyword", keyword);
            }
            if (startDate != null && endDate != null) {
                query.setParameter("startDate", startDate);
                query.setParameter("endDate", endDate);
            }
            query.addScalar("noticeId", StandardBasicTypes.STRING);
            query.addScalar("title", StandardBasicTypes.STRING);
            query.addScalar("type", StandardBasicTypes.INTEGER);
            query.addScalar("createUserId", StandardBasicTypes.STRING);
            query.addScalar("createTime", StandardBasicTypes.TIMESTAMP);
            query.addScalar("departmentId", StandardBasicTypes.STRING);
            query.addScalar("userId", StandardBasicTypes.STRING);
    
            query.setResultTransformer(new MyBasicTransformerAdapter());
    
            query.setFirstResult(startIndex);
            query.setMaxResults(pageSize);
            List<NoticePageListVO> items = query.list();

    中的

    query.addScalar("createTime", StandardBasicTypes.DATE);

    这边要改成
    query.addScalar("createTime", StandardBasicTypes.TIMESTAMP);

    注意:改成TIME也不行,一定要是TIMESTAMP

  • 相关阅读:
    协程方法的开启、关闭以及传参
    五种访问修饰符
    多态之虚方法、抽象类、接口
    递归算法
    继承之构造方法
    鼠标相关操作(Cursor类及相关API)
    遇到的问题(七)
    遇见的问题(六)
    遇见的问题(五)
    函数VS对象
  • 原文地址:https://www.cnblogs.com/grey-wolf/p/9203428.html
Copyright © 2011-2022 走看看