我正在使用带有角度2的Jhipster 4来创建应用程序。我想显示父实体用户将具有子实体列表的选项卡的选项卡。 客户和用户将拥有“任务和地址”选项卡。我知道如何将它们放入选项卡并使用单独的findByUserId()和findByCustomerId()选择列表。
我想避免为每个父元素创建这些方法,例如 findByPersonId()。
有没有明确的方法呢?
实体客户{ name需要的字符串, }
实体人{ name需要的字符串, }
实体任务{ name需要的字符串 } 实体Adres { name需要的字符串 }
关系OneToMany { 客户{tasks}到任务{customer(name)}, 人{任务}到任务{person(name)} }
query(req?: any): Observable<Response> {
let options = this.createRequestOption(req);
return this.http.get(this.resourceUrl, options)
.map((res: any) => this.convertResponse(res))
;
}
...
private createRequestOption(req?: any): BaseRequestOptions {
let options: BaseRequestOptions = new BaseRequestOptions();
if (req) {
let params: URLSearchParams = new URLSearchParams();
params.set('page', req.page);
params.set('size', req.size);
if (req.sort) {
params.paramsMap.set('sort', req.sort);
}
params.set('query', req.query);
options.search = params;
}
return options;
}
TaskRepository.ts
/**
* Spring Data JPA repository for the Task entity.
*/
@SuppressWarnings("unused")
public interface TaskRepository extends JpaRepository<Task,Long> {
@Query("select task from Task task where person.id =:id")
public List<Task> findByPersonId(@Param("id") Long id);
@Query("select task from Task task where customer.id =:id")
public List<Task> findByCustomerId(@Param("id") Long id);
}
TaskResource.ts
/**
* GET /tasks : get all the tasks.
*
* @return the ResponseEntity with status 200 (OK) and the list of tasks in body
*/
@GetMapping("/tasks")
@Timed
public List<Task> getAllTasks() {
log.debug("REST request to get all Tasks");
List<Task> tasks = taskRepository.findAll();
return tasks;
}