JHipster搜索实体,按其实体领域 [英] JHipster Search entity by field of his entity

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

问题描述

我有比赛实体.他与奖品实体有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的事实,我假设您启用了

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
  • 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字段(添加字段和获取/设置者).您还需要在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天全站免登陆