CUBA在查询语句如何添加参数

时间:2022-07-06 16:42:21

browse.xml中的collectionDatasource 可以添加查询语句,使用 “= :custom$param”  的形式

<collectionDatasource id="procActorsDs"
class="com.haulmont.bpm.entity.ProcActor"
view="procActor-browse">
<query>
<![CDATA[
select pa from bpm$ProcActor pa where pa.procInstance.id = :custom$procInstance
order by pa.procRole.order, pa.order
]]>
</query>
</collectionDatasource>

然后在后台Controller类中添加这个参数,datasoure.refresh(params)

public void refresh() {
Map<String, Object> params = new HashMap<>();
params.put("procInstance", procInstance);
procActorsDs.refresh(params);
}

如果是在后台中查询,那参数设置就跟JPQL很像了

public static ExcelTable findExcelTableById(DataManager dataManager, UUID entityId) {
LoadContext ctx = LoadContext.create(ExcelTable.class).setView("_local");
ctx.setQueryString("select et from cip$ExcelTable et where et.id = :entityId")
.setParameter("entityId", entityId);
return (ExcelTable) dataManager.load(ctx);
}