• 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

  • 相关阅读:
    linux常用命令
    Nfs的简单了解
    关于快速排序的学习
    The goal you specified requires a project to execute but there is no POM in this directory
    TeamCity编译执行selenium上传窗口脚本缺陷
    插入排序
    选择排序
    冒泡排序
    使用.bat文件运行ant的build.xml
    性能测试工具Loadrunner使用经验小结(原创更新版)
  • 原文地址:https://www.cnblogs.com/grey-wolf/p/9203428.html
Copyright © 2020-2023  润新知