关于 Spring boot QueryDsl 在编译时到不到父类
資深大佬 : glacial 1
我在 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 基本上不会有变化了所以我觉得可以这么做
不知道大家还有没有更好的办法
大佬有話說 (4)