CustomSQLUtil 在使用 Liferay 7 进行查询检索期间获取空值

CustomSQLUtil gets null value during query retrieval with Liferay 7

虽然我在 Liferay 6.2 中使用 CustomSQLUtil class 没有问题,但我在 Liferay 7 中遇到了这个 class 的新版本的问题。确实,get 方法 returns null 而不是预期的查询。

有人转载了吗?

这是我在 Eclipse Mars 中上次测试的描述:

  1. 在我的 Liferay 工作区中,我在服务模块的 build.gradle 中添加了以下行

compileOnly 组:"com.liferay",名称:"com.liferay.portal.dao.orm.custom.sql",版本:“1.0.5”

  1. gradle 刷新后,我可以在我的 FooFinderImpl class 中使用 CustomSQLUtil class 来检索适当的查询。

  2. 此查询已写入 default.xml 文件中,该文件已放入 Liferay 7 文档中提到的 src/custom-sql 文件夹中:

https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/custom-sql

我试过很多地方(在 META-INF 中,在资源中..),我什至尝试扩展 CustomSQL 本机 class 来获取配置,但是CustomSQLUtil class returns 始终为 null 而不是 sql 查询。

PS :我注意到这个新的 "CustomSQLUtil.get" 方法现在有 2 个参数,除了查询 ID 之外还请求了 class。在这个 class 参数中,我输入了 "Foo.class" 值。

有人知道是否需要配置吗?是否必须配置 classpath 或 bundlecontext?

尽量避免使用 CustomSQLUtil。而是尝试直接在您的查找器方法中使用查询,例如 字符串 sql="select * from Foo_Foo where name=?" 希望对您有所帮助!!

要使其正常工作,请在 foo-service/src/main/resources 中添加 custom-sql/default.xml,然后在 FooFinderImpl 中以这种方式使用 CustomSQLUtil

CustomSQLUtil.get(getClass(),CONSTANT_QUERY_ID); //id of query in default.xml

这是 github https://github.com/bruinen/liferay-services-example

上的示例