我正在学习使用JHipster,无法弄清楚如何使用创建自定义查询.
在我的项目中,我有Orders表格DeliveryDay和Week字段,并且只想显示当周当天的订单.DeliveryDay和Week的int值为(1-7和0-2)
所以OrdersRepository.java我添加了这样的自定义查询:
public interface OrdersRepository extends JpaRepository<Orders,Long> {
Page<Orders> findByDeliveryDayAndWeek(int weekday, int week, pageable);
Run Code Online (Sandbox Code Playgroud)
在OrdersResource.java我添加了这个:
@RequestMapping(value = "/today",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<List<Orders>> getOrdersForToday(Pageable pageable)
throws URISyntaxException {
log.debug("REST request to get a page of Orderss");
Page<Orders> page = ordersRepository.findByDeliveryDayAndWeek(1, 0, pageable);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/today");
return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
Run Code Online (Sandbox Code Playgroud)
我还添加today.html(复制orders.html)和today.js
'use strict';
angular.module('fruitcrmApp')
.config(function ($stateProvider) …Run Code Online (Sandbox Code Playgroud) 我遇到了一个问题。我有一个input元素和函数来显示“加载”动画。问题是,一旦我放下文件或单击并选择它们,“加载”动画就会显示几秒钟的延迟(多个文件或大文件)。
注意:使用 Angular 2+ 制作的解决方案这就是原因(change)
解决方案一:
HTML:
<input type="file" multiple="true" (change)="uploadImgs($event)"/>
Run Code Online (Sandbox Code Playgroud)
JS:
uploadImgs(event: any) {
console.log('START UPLOAD!')
this.spinnerService.start();
///restOfTheLogic...}
Run Code Online (Sandbox Code Playgroud)
解决方案2:使用onDrop事件触发this.spinnerService.start();显示动画
HTML:
<div (drop)="spinnerService.start();">
<input type="file" multiple="true (change)="uploadImgs($event)"/>
</div>
Run Code Online (Sandbox Code Playgroud)
解决方案 3:触发这两个函数onChange/onDrop
HTML:
<input type="file" multiple="true (change)="spinnerService.start(); uploadImgs($event)"/>
Run Code Online (Sandbox Code Playgroud)
输出:在所有情况下,放置文件后,我都可以console.log('START UPLOAD!')立即在控制台中看到输出,但在动画实际出现之前会出现延迟。
动画功能简单来说:
start() {
document.getElementById('loading').classList.remove('hidden');
Run Code Online (Sandbox Code Playgroud)
}
我试着自己去寻找。但是堆叠为什么第一行console.log立即执行而第二行this.spinnerService.start();延迟执行?在操作 DOM 元素之前是否等待files读取数据或执行其他操作?
有什么想法可以避免这种延迟吗?