JHipster 按实体字段搜索实体 [英] JHipster Search entity by field of his entity

查看:32
本文介绍了JHipster 按实体字段搜索实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有锦标赛实体.他与 Prize 实体有 OneToOne 关系.奖品实体已备案金额".因此,如果我想搜索在 2 个值之间有奖励的锦标赛,我该如何使用 JHipster QueryService 来做到这一点?

I have Tournament entity. He have OneToOne relation with Prize entity. Prize entity have filed "amount". So if i want to do search Tournaments that have prize between some 2 values how can i do that using JHipster QueryService ?

推荐答案

基于您使用 QueryService 的事实,我假设您启用了 Filtering 选项 生成实体时.要查询 Tournament 实体的 Prize 金额介于两个值之间,需要添加一些内容.

Based on the fact you are using QueryService, I'm assuming you enabled the Filtering option when generating your entities. To query Tournament entities with a Prize amount between two values, a few things need to be added.

TournamentQueryService 中,添加以下内容以构建 prize.amount 字段的规范:

In TournamentQueryService, add the following to build a specification for the prize.amount field:

if (criteria.getPrizeAmount() != null) {
    specification = specification.and(buildReferringEntitySpecification(criteria.getPrizeAmount(), Tournament_.prize, Prize_.amount));
}

TournamentCriteria 中,为prizeAmount 过滤器添加一个字段:private DoubleFilter PrizeAmount;.还要添加 getter 和 setter.

In TournamentCriteria, add a field for the prizeAmount filter: private DoubleFilter prizeAmount;. Also add getters and setters.

现在您可以通过 Swagger(在菜单 Admin->API 下)测试请求并根据奖金金额字段过滤锦标赛.

Now you can test the request through Swagger (under menu Admin->API) and filter tournaments based on the prize amount field.

如果要在客户端进行这个查询,需要在HTTP请求中添加两个参数:

If you want to make this query in the client, you need to add two parameters to the HTTP request:

  • prizeAmount.greaterOrEqualThan
  • prizeAmount.lessOrEqualThan

您可以将它们添加到 query 调用中,如下所示,这将返回奖金金额 >= 1 和 <= 5(例如 Angular)的锦标赛:

You can add them in the query call like below, which will return Tournaments with prize amounts >= 1 and <= 5 (example is Angular):

loadAll() {
    this.tournamentService.query({
        'prizeAmount.greaterOrEqualThan': 1,
        'prizeAmount.lessOrEqualThan': 5
    }).subscribe(
        (res: HttpResponse<ITournament[]>) => {
            this.tournaments = res.body;
        },
        (res: HttpErrorResponse) => this.onError(res.message)
    );
}

<小时>

如果您希望TournamentDTO 包含奖金金额作为字段,则需要在TournamentDTO 中添加prizeAmount 字段(添加字段和 getter/setter).您还需要在 TournamentMapper 中添加 @Mapping(source = "prize.amount", target = "prizeAmount") 以将奖品数据映射到 中的该字段>TournamentDTO.


If you want the TournamentDTO to contain the prize amount as a field, the prizeAmount field needs to be added in the TournamentDTO (add field and getters/setters). You also need to add @Mapping(source = "prize.amount", target = "prizeAmount") in TournamentMapper to map the prize data to that field in the TournamentDTO.

这篇关于JHipster 按实体字段搜索实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆