首页 > 解决方案 > Spring Boot 上的 QueryDSL 问题

问题描述

我完全按照http://zetcode.com/springboot/querydsl/上的描述设置了我的项目。QCity 类是自动生成的。

这是@SpringBootApplication注解类的方法:

@Override
    public void run(String... args) throws Exception {

        QCity qCity = QCity.city;

        JPAQuery query = new JPAQuery(entityManager);

        query.from(qCity).where(qCity.name.eq("Bratislava")).distinct();
        var c1 = query.fetch();

        logger.info("{}", c1);

}

我执行了 maven clean 然后安装

但是我在尝试执行时收到了这个错误日志:

java.lang.Error: Unresolved compilation problems: 
    QCity cannot be resolved to a type
    QCity cannot be resolved to a variable
    var cannot be resolved to a type

    at grupo.artefatoX2.ArtefatoX2Application.run(ArtefatoX2Application.java:37) ~[classes/:na]

正好指向这条线 QCity qCity = QCity.city;

日志被缩短了。

什么地方出了错 ??

标签: javaspringspring-bootquerydsl

解决方案


您需要生成来源:

mvn generate-sources

或者包括这里提到的插件:QueryDsl - How to create Q classes with maven? 在您的 pom 中如下所示并运行 mvn clean install。


推荐阅读