jhipster client side pass entity filter to server

2019-07-06 03:03发布

问题:

After reading http://www.jhipster.tech/entities-filtering/, I can get my jhipster generated applicaiton filter work on postman.

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?

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;

};

After reading JHipster: Filtering entities with criteria - intended Angular client-side approach I tried serveral ways to either pass a {} or [] to query or fitler. However, I cannot make it to work.

In the server side, log says: RequestResource.getAllRequests() with argument[s] = [RequestCriteria{}, Page request [number: 0, size 21, sort: happenDate: DESC]]

The "RequestCriteria{}" cound not get anything I passed in.

Anyone has idear how can I make it work? Thanks a lot.

回答1:

as a temp way, here is my current way to pass the filter from client to server:

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"
    };

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);