JHipster增加查询功能(简便方法)

以公司company模块为例

1、在company.component.html增加查询按钮

<div class="row">
<div class="col-sm-12">
<form name="searchForm" class="form-inline">
<div class="input-group w-100 mt-3">
<input type="text" class="form-control" [(ngModel)]="currentSearch" id="currentSearch" name="currentSearch" placeholder="{{ 'faceMachineApp.company.home.search' | translate }}">
<button class="input-group-append btn btn-info" (click)="transition()">
<fa-icon [icon]="'search'"></fa-icon>
</button>
<button class="input-group-append btn btn-danger" (click)="clear()" *ngIf="currentSearch">
<fa-icon [icon]="'trash-alt'"></fa-icon>
</button>
</div>
</form>
</div>
</div>
2、在company.component.ts增加查询字段、参数和方法

currentSearch: string;
constructor(
......
this.currentSearch = '';
}
loadAll() {
this.companyService
.query({
page: this.page - 1,
size: this.itemsPerPage,
sort: this.sort(),
search: this.currentSearch
})
.subscribe(
(res: HttpResponse<ICompany[]>) => this.paginateCompanies(res.body, res.headers),
(res: HttpErrorResponse) => this.onError(res.message)
);
}
3、在company.component.ts文件clean()方法中增加以下代码:

this.currentSearch = '';
4、在zh-cn/company.json增加faceMachineApp.company.home.search国际化资源

"search": "查找 Company",
5、在en/company.json增加faceMachineApp.company.home.search国际化资源

"search": "Search for Company",
6、在manager\src\main\java\com\xadhsd\manager\web\rest\CompanyResource.java修改以下方法:

/**
* {@code GET /companies} : get all the companies.
*
* @param pageable the pagination information.
* @param criteria the criteria which the requested entities should match.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of companies in body.
*/
@GetMapping(value = "/companies")
public ResponseEntity<List<CompanyDTO>> getAllCompanies(
CompanyCriteria criteria, Pageable pageable,
@RequestParam MultiValueMap<String, String> queryParams,
UriComponentsBuilder uriBuilder) {
log.debug("REST request to get Companies by criteria: {}", criteria);
if (!StringUtils.isEmpty(queryParams.get("search")) &&
!StringUtils.isEmpty(queryParams.get("search").get(0))) {
String companyName = queryParams.get("search").get(0);
StringFilter companyNameStringFilter = new StringFilter();
companyNameStringFilter.setContains(companyName);
criteria.setCompanyName(companyNameStringFilter);
}
Page<CompanyDTO> page = companyQueryService.findByCriteria(criteria, pageable);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(uriBuilder.queryParams(queryParams), page);
return ResponseEntity.ok().headers(headers).body(page.getContent());

 

posted @ 2019-07-09 15:57  大强的博客  阅读(609)  评论(0编辑  收藏  举报