Вот моя попытка решить проблему, основанную на работе других, но она не работает, потому что передача в VkaResource приводит к VkaCriteria со всеми полями, равными нулю:
Выдержка из VkaResource:
/**
* GET /vkas : get all the vkas.
*
* @param pageable the pagination information
* @param criteria the criterias which the requested entities should match
* @return the ResponseEntity with status 200 (OK) and the list of vkas in body
*/
@GetMapping("/vkas")
@Timed
public ResponseEntity<List<VkaDTO>> getAllVkas(VkaCriteria criteria, Pageable pageable) {
log.debug("REST request to get Vkas by criteria: {}", criteria);
Page<VkaDTO> page = vkaQueryService.findByCriteria(criteria, pageable);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/vkas");
return ResponseEntity.ok().headers(headers).body(page.getContent());
}
Вот код Angular от vka.Component.ts:
this.criteria = {
mkt1: null,
vnr: null,
wirkungGueltigAb: null,
wirkungGueltigBis: null,
areSet() {
return this.mkt1 != null || this.vnr != null || this.wirkungGueltigAb != null || this.wirkungGueltigBis != null;
},
clear() {
this.mkt1 = null;
this.vnr = null;
this.wirkungDatAb = null;
this.wirkungDatBis = null;
}
};
}
loadAll() {
const criteria = [];
if (this.criteria.areSet()) {
if (this.criteria.mkt1 != null && this.criteria.mkt1 !== '') {
criteria.push({key: 'mkt1.equals', value: this.criteria.mkt1});
}
if (this.criteria.vnr != null && this.criteria.vnr >= 0) {
criteria.push({key: 'vnr.equals', value: this.criteria.vnr});
}
if (this.criteria.wirkungGueltigAb != null && this.criteria.wirkungGueltigAb >= 0) {
criteria.push({key: 'wirkungGueltigAb.equals', value: this.criteria.wirkungGueltigAb});
}
if (this.criteria.wirkungGueltigBis != null && this.criteria.wirkungGueltigBis >= 0) {
criteria.push({key: 'wirkungGueltigBis.equals', value: this.criteria.wirkungGueltigBis});
}
}
this.vkaService
.query({
criteria,
page: this.page - 1,
size: this.itemsPerPage,
sort: this.sort()
})
.subscribe(
(res: HttpResponse<IVkaVka[]>) => this.paginateVkas(res.body, res.headers),
(res: HttpErrorResponse) => this.onError(res.message)
);
}
Вот код запроса-util.ts
import { HttpParams } from '@angular/common/http';
export const createRequestOption = (req?: any): HttpParams => {
let options: HttpParams = new HttpParams();
if (req) {
Object.keys(req).forEach(key => {
if (key !== 'sort') {
options = options.set(key, req[key]);
}
});
if (req.sort) {
req.sort.forEach(val => {
options = options.append('sort', val);
});
}
}
return options;
};
Итак, что женеправильно?