gpt4 book ai didi

spring - JHipster-使用来自Elasticsearch的API调用对实体进行动态过滤-如何以适当的方式使用angular5实现它?

转载 作者:行者123 更新时间:2023-12-02 22:36:36 25 4
gpt4 key购买 nike

我是Jhipster的新手,但是我也不是一位经验丰富的开发人员。因此,我生成了一个Jhipster项目,并且需要一个带有动态column-filtering选项的简单表。我已经看到backend-side上从Jhipster生成的所有东西都需要。

所以我有生成的类 CustomerQueryService.java

    @Transactional(readOnly = true)
public List<Customer> findByCriteria(CustomerCriteria criteria) {
log.debug("find by criteria : {}", criteria);
final Specifications<Customer> specification = createSpecification(criteria);
return customerRepository.findAll(specification);
}

/**
* Return a {@link Page} of {@link Customer} which matches the criteria from the database
* @param criteria The object which holds all the filters, which the entities should match.
* @param page The page, which should be returned.
* @return the matching entities.
*/
@Transactional(readOnly = true)
public Page<Customer> findByCriteria(CustomerCriteria criteria, Pageable page) {
log.debug("find by criteria : {}, page: {}", criteria, page);
final Specifications<Customer> specification = createSpecification(criteria);
return customerRepository.findAll(specification, page);
}

/**
* Function to convert CustomerCriteria to a {@link Specifications}
*/
private Specifications<Customer> createSpecification(CustomerCriteria criteria) {
Specifications<Customer> specification = Specifications.where(null);
if (criteria != null) {
if (criteria.getId() != null) {
specification = specification.and(buildSpecification(criteria.getId(), Customer_.id));
}
if (criteria.getLastName() != null) {
specification = specification.and(buildStringSpecification(criteria.getLastName(), Customer_.lastName));
}
if (criteria.getName() != null) {
specification = specification.and(buildStringSpecification(criteria.getName(), Customer_.name));
}
if (criteria.getPhoneNumber() != null) {
specification = specification.and(buildRangeSpecification(criteria.getPhoneNumber(), Customer_.phoneNumber));
}
if (criteria.getProvider() != null) {
specification = specification.and(buildStringSpecification(criteria.getProvider(), Customer_.provider));
}
if (criteria.getVoNumber() != null) {
specification = specification.and(buildRangeSpecification(criteria.getVoNumber(), Customer_.voNumber));
}
if (criteria.getTransactionType() != null) {
specification = specification.and(buildStringSpecification(criteria.getTransactionType(), Customer_.transactionType));
}
if (criteria.getKomponent() != null) {
specification = specification.and(buildStringSpecification(criteria.getKomponent(), Customer_.komponent));
}
if (criteria.getActivationDate() != null) {
specification = specification.and(buildRangeSpecification(criteria.getActivationDate(), Customer_.activationDate));
}
if (criteria.getSimNumber() != null) {
specification = specification.and(buildRangeSpecification(criteria.getSimNumber(), Customer_.simNumber));
}
if (criteria.getOrderNumber() != null) {
specification = specification.and(buildRangeSpecification(criteria.getOrderNumber(), Customer_.orderNumber));
}
if (criteria.getTariff() != null) {
specification = specification.and(buildStringSpecification(criteria.getTariff(), Customer_.tariff));
}
if (criteria.getOption() != null) {
specification = specification.and(buildStringSpecification(criteria.getOption(), Customer_.option));
}
if (criteria.getHardware() != null) {
specification = specification.and(buildStringSpecification(criteria.getHardware(), Customer_.hardware));
}
if (criteria.getImei() != null) {
specification = specification.and(buildRangeSpecification(criteria.getImei(), Customer_.imei));
}
if (criteria.getPurchasingPrice() != null) {
specification = specification.and(buildRangeSpecification(criteria.getPurchasingPrice(), Customer_.purchasingPrice));
}
if (criteria.getRetailPrice() != null) {
specification = specification.and(buildRangeSpecification(criteria.getRetailPrice(), Customer_.retailPrice));
}
if (criteria.getProvision() != null) {
specification = specification.and(buildRangeSpecification(criteria.getProvision(), Customer_.provision));
}
if (criteria.getMarge() != null) {
specification = specification.and(buildRangeSpecification(criteria.getMarge(), Customer_.marge));
}
if (criteria.getHwWkz() != null) {
specification = specification.and(buildRangeSpecification(criteria.getHwWkz(), Customer_.hwWkz));
}
if (criteria.getPaid() != null) {
specification = specification.and(buildSpecification(criteria.getPaid(), Customer_.paid));
}
if (criteria.getEmployee() != null) {
specification = specification.and(buildStringSpecification(criteria.getEmployee(), Customer_.employee));
}
if (criteria.getComment() != null) {
specification = specification.and(buildStringSpecification(criteria.getComment(), Customer_.comment));
}
}
return specification;
}

以及另一个生成的类 CustomerCriteria.java
public class CustomerCriteria implements Serializable {
private static final long serialVersionUID = 1L;


private LongFilter id;

private StringFilter lastName;

private StringFilter name;

private LongFilter phoneNumber;

private StringFilter provider;

private LongFilter voNumber;

private StringFilter transactionType;

private StringFilter komponent;

private LocalDateFilter activationDate;

private LongFilter simNumber;

private LongFilter orderNumber;

private StringFilter tariff;

private StringFilter option;

private StringFilter hardware;

private LongFilter imei;

private BigDecimalFilter purchasingPrice;

private BigDecimalFilter retailPrice;

private BigDecimalFilter provision;

private BigDecimalFilter marge;

private BigDecimalFilter hwWkz;

private BooleanFilter paid;

private StringFilter employee;

private StringFilter comment;

public CustomerCriteria() {
}

public LongFilter getId() {
return id;
}

public void setId(LongFilter id) {
this.id = id;
}

public StringFilter getLastName() {
return lastName;
}

public void setLastName(StringFilter lastName) {
this.lastName = lastName;
}

public StringFilter getName() {
return name;
}

public void setName(StringFilter name) {
this.name = name;
}

public LongFilter getPhoneNumber() {
return phoneNumber;
}

public void setPhoneNumber(LongFilter phoneNumber) {
this.phoneNumber = phoneNumber;
}

public StringFilter getProvider() {
return provider;
}

public void setProvider(StringFilter provider) {
this.provider = provider;
}

public LongFilter getVoNumber() {
return voNumber;
}

public void setVoNumber(LongFilter voNumber) {
this.voNumber = voNumber;
}

public StringFilter getTransactionType() {
return transactionType;
}

public void setTransactionType(StringFilter transactionType) {
this.transactionType = transactionType;
}

public StringFilter getKomponent() {
return komponent;
}

public void setKomponent(StringFilter komponent) {
this.komponent = komponent;
}

public LocalDateFilter getActivationDate() {
return activationDate;
}

public void setActivationDate(LocalDateFilter activationDate) {
this.activationDate = activationDate;
}

public LongFilter getSimNumber() {
return simNumber;
}

public void setSimNumber(LongFilter simNumber) {
this.simNumber = simNumber;
}

public LongFilter getOrderNumber() {
return orderNumber;
}

public void setOrderNumber(LongFilter orderNumber) {
this.orderNumber = orderNumber;
}

public StringFilter getTariff() {
return tariff;
}

public void setTariff(StringFilter tariff) {
this.tariff = tariff;
}

public StringFilter getOption() {
return option;
}

public void setOption(StringFilter option) {
this.option = option;
}

public StringFilter getHardware() {
return hardware;
}

public void setHardware(StringFilter hardware) {
this.hardware = hardware;
}

public LongFilter getImei() {
return imei;
}

public void setImei(LongFilter imei) {
this.imei = imei;
}

public BigDecimalFilter getPurchasingPrice() {
return purchasingPrice;
}

public void setPurchasingPrice(BigDecimalFilter purchasingPrice) {
this.purchasingPrice = purchasingPrice;
}

public BigDecimalFilter getRetailPrice() {
return retailPrice;
}

public void setRetailPrice(BigDecimalFilter retailPrice) {
this.retailPrice = retailPrice;
}

public BigDecimalFilter getProvision() {
return provision;
}

public void setProvision(BigDecimalFilter provision) {
this.provision = provision;
}

public BigDecimalFilter getMarge() {
return marge;
}

public void setMarge(BigDecimalFilter marge) {
this.marge = marge;
}

public BigDecimalFilter getHwWkz() {
return hwWkz;
}

public void setHwWkz(BigDecimalFilter hwWkz) {
this.hwWkz = hwWkz;
}

public BooleanFilter getPaid() {
return paid;
}

public void setPaid(BooleanFilter paid) {
this.paid = paid;
}

public StringFilter getEmployee() {
return employee;
}

public void setEmployee(StringFilter employee) {
this.employee = employee;
}

public StringFilter getComment() {
return comment;
}

public void setComment(StringFilter comment) {
this.comment = comment;
}

@Override
public String toString() {
return "CustomerCriteria{" +
(id != null ? "id=" + id + ", " : "") +
(lastName != null ? "lastName=" + lastName + ", " : "") +
(name != null ? "name=" + name + ", " : "") +
(phoneNumber != null ? "phoneNumber=" + phoneNumber + ", " : "") +
(provider != null ? "provider=" + provider + ", " : "") +
(voNumber != null ? "voNumber=" + voNumber + ", " : "") +
(transactionType != null ? "transactionType=" + transactionType + ", " : "") +
(komponent != null ? "komponent=" + komponent + ", " : "") +
(activationDate != null ? "activationDate=" + activationDate + ", " : "") +
(simNumber != null ? "simNumber=" + simNumber + ", " : "") +
(orderNumber != null ? "orderNumber=" + orderNumber + ", " : "") +
(tariff != null ? "tariff=" + tariff + ", " : "") +
(option != null ? "option=" + option + ", " : "") +
(hardware != null ? "hardware=" + hardware + ", " : "") +
(imei != null ? "imei=" + imei + ", " : "") +
(purchasingPrice != null ? "purchasingPrice=" + purchasingPrice + ", " : "") +
(retailPrice != null ? "retailPrice=" + retailPrice + ", " : "") +
(provision != null ? "provision=" + provision + ", " : "") +
(marge != null ? "marge=" + marge + ", " : "") +
(hwWkz != null ? "hwWkz=" + hwWkz + ", " : "") +
(paid != null ? "paid=" + paid + ", " : "") +
(employee != null ? "employee=" + employee + ", " : "") +
(comment != null ? "comment=" + comment + ", " : "") +
"}";
}

并在我的 cusotmer.component.ts中
 searchByField(fieldName, fieldValue) {
if (!fieldValue) {
return this.clear();
}
this.page = 0;
this.fieldName = fieldName,
this.fieldValue = fieldValue;
this.router.navigate(['/customer', {
fieldName: this.fieldName,
fieldValue: this.fieldValue,
page: this.page,
sort: this.predicate + ',' + (this.reverse ? 'asc' : 'desc')
}]);
this.loadByField();
}

以及 customer.service.ts
    searchByField(req?: any): Observable<HttpResponse<Customer[]>> {
const options = createRequestOption(req);
return this.http.get<Customer[]>(this.resourceSearchFieldUrl, { params: options, observe: 'response' })
.map((res: HttpResponse<Customer[]>) => this.convertArrayResponse(res));
}

我现在想要的是将表中每一列的Searchqueries组合起来,并将其发送到elasticsearch api,并获得用于填充搜索的正确网址,如下所示:

enter image description here

但不幸的是,我无法组合搜索参数,也不知道如何修改它。我还将从最佳实践出发,还将使用 Jhipster已经生成的类,因为我认为这是最好的方法。任何人都知道如何修改它?非常感谢您提前阅读这个冗长的问题。

最佳答案

尝试:

searchByField(fieldName, fieldValue) {
if (!fieldValue) {
return this.clear();
}
this.page = 0;
this.router.navigate(['/customer', {
this.fieldName:this.fieldValue; // 'customerName.contains': 'Jackson',
page: this.page,
sort: this.predicate + ',' + (this.reverse ? 'asc' : 'desc')
}]);
this.loadByField();
}

关于spring - JHipster-使用来自Elasticsearch的API调用对实体进行动态过滤-如何以适当的方式使用angular5实现它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50296076/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com