问题描述
阅读 http://www.jhipster.tech/entities-filtering/ ,我可以在邮递员上使用jhipster生成的应用过滤器工作.
After reading http://www.jhipster.tech/entities-filtering/, I can get my jhipster generated applicaiton filter work on postman.
例如,我可以通过以下方式在邮递员上获得正确的结果: http://localhost:8080/api/requests?page = 0& size = 20& sort = model,asc& sort = id& id.in = 20000, 20001
For example I can get right result on postman with: http://localhost:8080/api/requests?page=0&size=20&sort=model,asc&sort=id&id.in=20000,20001
我的问题是如何使它在生成的角度客户端应用程序上工作?
my questions how can make it work on the generated angular client side app?
我看到在../shared文件夹中有"request-util.ts".它的内部有一个名为查询"和过滤器"的参数.
I saw that in the ../shared folder it has "request-util.ts". Inside it, there is parameter named "query" and "filter".
export const createRequestOption = (req?: any): BaseRequestOptions => {
const options: BaseRequestOptions = new BaseRequestOptions();
if (req) {
const params: URLSearchParams = new URLSearchParams();
params.set('page', req.page);
params.set('size', req.size);
if (req.sort) {
params.paramsMap.set('sort', req.sort);
}
params.set('query', req.query);
params.set('filter', req.filter);
options.params = params;
}
return options;
};
阅读 JHipster:使用条件过滤实体-预期的Angular客户端方法我尝试了服务器方式来传递{}或[]来进行查询或拟合.但是,我无法使其正常工作.
After reading JHipster: Filtering entities with criteria - intended Angular client-side approachI tried serveral ways to either pass a {} or [] to query or fitler. However, I cannot make it to work.
在服务器端,日志说:RequestResource.getAllRequests(),参数为[s] = [RequestCriteria {},页面请求[数字:0,大小21,排序:巧遇日期:DESC]]
In the server side, log says: RequestResource.getAllRequests() with argument[s] = [RequestCriteria{}, Page request [number: 0, size 21, sort: happenDate: DESC]]
"RequestCriteria {}"字词没有得到我传入的任何内容.
The "RequestCriteria{}" cound not get anything I passed in.
任何人都知道我该如何使它起作用?非常感谢.
Anyone has idear how can I make it work? Thanks a lot.
推荐答案
作为临时方法,这是我当前将过滤器从客户端传递到服务器的方法:
as a temp way, here is my current way to pass the filter from client to server:
为传递给模型 some.service.ts
query(req?:any)
函数的参数req对象组成过滤器属性
compose a filter property for the paramater req object pass to model some.service.ts
query(req?:any)
function like this
req.filter = {
'contactName.contains': "Smith"
'contactNumber.contains':"186"
};
,然后更改../shared文件夹 request-util.ts
文件
and then change the ../shared folder request-util.ts
file
if (req.filter) {
for (const k in req.filter) {
if (k) {
params.append(k, req.filter[k]);
}
}
}
// params.set('filter', req.filter);
这篇关于jhipster客户端将实体过滤器传递到服务器端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!