以下本机sql查询(Sybase)的等效querydsl代码是什么?

时间:2020-04-20 11:54:14

标签: spring-boot datetime spring-data-jpa querydsl

select d.drvr_id, z.reg_id , convert(varchar,d.arrival_dt,100),0 as DrvrCount 
from driverTable d,reg_zip z where d.model_flag=1 

arrival_dt是一个时间戳。

我在存储库文件中尝试了以下代码。得到一些汇编。请给我建议一种方法。我想将时间戳对象转换为日期字符串。

@SuppressWarnings("unchecked")
    List<Tuple> GetDrivers() {

        QRegZipModel regZip = QRegZipModel.regZipModel;
        QDriverModel driverModel = QDriverModel.driverModel;
        JPAQueryFactory queryFactory = new JPAQueryFactory(entityManager);
        //Expression<String> dateExpr = Expressions.stringTemplate(String.class,"convert(varchar, {0}, 100)", driverModel.arrival_dt);
        //NumberPath<Integer> dummy = Expressions.numberPath(Integer.class, "dummy");
        //String dateAlias = "MM/dd/yyyy"; 
        List<Tuple> driversList = null;
        driversList = queryFactory.select(driverModel.drvr_id, regZip.reg_id ,SQLExpressions.date(driverModel.arrival_dt)
        ,count(0) as DrvrCount
                ).from(driverModel, regZip)
                .where(driverModel.model_flag.eq(true))
                .createQuery().getResultList();

        return driversList;
    }

0 个答案:

没有答案