我有一个使用Spring Data MongoDB的Spring Boot Gradle项目。
为了生成查询类型类,我必须运行gradle构建任务。
在IntelliJ中保存文件时,有没有办法创建查询类型类?我已经在项目中启用了注释处理。
我希望有一个像lombok插件这样的行为,在这个行为中不需要构建项目来查看更改。
以下是我的build.gradle文件:
buildscript {
ext {
springBootVersion = '2.0.0.RELEASE'
}
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("io.franzbecker:gradle-lombok:1.11")
classpath("gradle.plugin.com.ewerk.gradle.plugins:querydsl-plugin:1.0.9")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: "io.franzbecker.gradle-lombok"
apply plugin: "com.ewerk.gradle.plugins.querydsl"
group = 'com.henrique'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-mongodb')
compile("com.querydsl:querydsl-mongodb:4.1.4")
compileOnly("com.querydsl:querydsl-apt:4.1.4")
testCompile('org.springframework.boot:spring-boot-starter-test')
}
querydsl {
springDataMongo = true
querydslSourcesDir = "$buildDir/generated/source/app/main"
}
sourceSets {
main {
java {
srcDir "$buildDir/generated/source/app/main"
}
}
}
这是我的域名实体:
@Data
@Builder
@Document
public class Customer {
@Id
private String id;
private String firstName;
private String lastName;
private String zipCode;
}
这是生成的查询类型:
@Generated("com.querydsl.codegen.EntitySerializer")
public class QCustomer extends EntityPathBase<Customer> {
private static final long serialVersionUID = -1386833698L;
public static final QCustomer customer = new QCustomer("customer");
public final StringPath firstName = createString("firstName");
public final StringPath id = createString("id");
public final StringPath lastName = createString("lastName");
public final StringPath zipCode = createString("zipCode");
public QCustomer(String variable) {
super(Customer.class, forVariable(variable));
}
public QCustomer(Path<? extends Customer> path) {
super(path.getType(), path.getMetadata());
}
public QCustomer(PathMetadata metadata) {
super(Customer.class, metadata);
}
}