
我在 springboot 的项目中使用了 QueryDsl, 如果使用了父类并且不在一个包下在编译时会报错找不到父类的"Q 类" 例如 :QRootEntity
RootEntity 类路径是在 com.zp.mars.entity 中 
User 类路径是在 com.zp.mars.user.domain 中 
这个时候去编译 User 类会报不找到 QRootEntity 类, 也就是说 QueryDsl 插件是默认不会找到父类并生成父类的 Q 类的 这个时候有两种解决办法
1.项目中加上一个 package-info 类
@QueryEntities(value = {RootEntity.class}) package com.zp.mars.entity; import com.querydsl.core.annotations.QueryEntities; import com.zp.mars.entity.RootEntity; 2.因为我用的是微服务这样在每个项目的中加上 package-info 类我觉得有点麻烦.所以我就把生成好的 QRootEntity 类拷到了 com.zp.mars.entity 下 这样也可以编译通过. 因为我的 RootEntity 基本上不会有变化了所以我觉得可以这么做
不知道大家还有没有更好的办法
1 Jooooooooo Oct 3, 2020 放到一个 common 包里, 大家都引这个包. |
2 glacial OP @Jooooooooo 是的 我的 com.zp.mars.entity.RootEntity 就是个一个 common 包里面 |
3 crclz Oct 3, 2020 歪个楼,我个人认为 QueryDSL 很无用。 事务类请求直接使用 JpaRepository 。 查询类请求直接写 sql,一方面是因为 sql 本身是一个很成熟、易编写、易理解的语言,另一方面是因为 IDEA 有 sql 智能提示。 |
4 wangyanrui Oct 3, 2020 via Android @glacial common 包也导入 querydsl 的 jar 和 maven 插件即可 |
5 CaspianJou Dec 23, 2023 @crclz 主要动态条件这种场景,Specification 写起来太繁琐,代码可读性也不够,这时候 QueryDSL 就很香 |