QueryDSL骆驼案例到没有JPA /休眠的蛇案例

尝试找到任何在蛇形情况下用列组成SQL查询的方法。然后,SQL查询将以纯文本形式提供给Spring Data R2DBC Databaseclient执行程序。我没有使用jpa / hibernate,jdo或mongo模块。

如何将列名转换为蛇形?也许有一些配置,或者可以覆盖某些东西以实现此技巧。由于除了使用regex方法以大写字符的形式将整个组合SQL查询作为纯文本进行检查以将其转换为前面附加下划线的方式外,我再也没有任何想法。

build.gradle:

plugins {
    id 'idea'
    id 'java'
    id 'org.springframework.boot' version '2.2.1.RELEASE'
}

apply plugin: 'io.spring.dependency-management'

ext {
    queryDslVersion = '4.2.2'
    javaxAnnotationVersion = '1.3.2'
}

dependencies {
    implementation('org.springframework.boot:spring-boot-starter-webflux')

    compile("com.querydsl:querydsl-sql:${queryDslVersion}")

    compileonly('org.projectlombok:lombok')

    annotationProcessor('org.projectlombok:lombok')
    annotationProcessor("com.querydsl:querydsl-apt:${queryDslVersion}:general")
    annotationProcessor("javax.annotation:javax.annotation-api:${javaxAnnotationVersion}")

    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage',module: 'junit-vintage-engine'
    }
    testImplementation('io.projectreactor:reactor-test')
}

idea {
    module {
        sourceDirs += file('generated/')
        generatedSourceDirs += file('generated/')
    }
}

查询:

 public Flux<Foo> findByCollectionQuery(FooCollectionQuery collectionQuery) {
        var foo = QFoo.foo;
        var bar = QBar.bar;
        var predicates = new BooleanBuilder();

        var query = new PostgreSQLQuery<>(null);
        query.select(foo,bar.someProperty)
             .from(foo)
             .leftJoin(bar).on(bar.id.eq(foo.barId));

        collectionQuery.getFooId().ifPresent(fooId -> predicates.and(foo.fooId.eq(fooId)));
        ...

        query.where(predicates).orderBy(payment.created.desc())
             .offset(collectionQuery.getPageable().getOffset())
             .limit(collectionQuery.getPageable().getPageSize());

        return this.client.execute(query.getSQL().getSQL())
                          .as(Foo.class)
                          .fetch()
                          .all();
    }
evilyue 回答:QueryDSL骆驼案例到没有JPA /休眠的蛇案例

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2685826.html

大家都在问