跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • 关于 Spring boot QueryDsl 在编译时到不到父类
未分類
1 10 月 2020

关于 Spring boot QueryDsl 在编译时到不到父类

关于 Spring boot QueryDsl 在编译时到不到父类

資深大佬 : glacial 1

我在 springboot 的项目中使用了 QueryDsl, 如果使用了父类并且不在一个包下在编译时会报错找不到父类的”Q 类” 例如 :QRootEntity

RootEntity 类路径是在 com.zp.mars.entity 中 关于 Spring boot QueryDsl 在编译时到不到父类

User 类路径是在 com.zp.mars.user.domain 中 关于 Spring boot QueryDsl 在编译时到不到父类

这个时候去编译 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)

  • 資深大佬 : Jooooooooo

    放到一个 common 包里, 大家都引这个包.

  • 主 資深大佬 : glacial

    @Jooooooooo 是的 我的 com.zp.mars.entity.RootEntity 就是个一个 common 包里面

  • 資深大佬 : crclz

    歪个,我个人认为 QueryDSL 很无用。

    事务类请求直接使用 JpaRepository 。

    查询类请求直接写 sql,一方面是因为 sql 本身是一个很成熟、易编写、易理解的语言,另一方面是因为 IDEA 有 sql 智能提示。

  • 資深大佬 : wangyanrui

    @glacial common 包也导入 querydsl 的 jar 和 maven 插件即可

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具