jHipster:"GreaterThan,LessThan"日期时间的搜索条件



在我的jHipster项目中,我想按日期时间范围搜索行。我的代码片段是:

产品查询视图组件.html

<div class="input-group date" id='datetimepicker'>
    <input id="field_dateStart" #dateStart="ngbDatepicker" [(ngModel)]="criteriaByStartDate"/>
    <input id="field_dateEnd"  #dateEnd="ngbDatepicker" [(ngModel)]="criteriaByEndDate"/>
    <button (click)="findByCriteria()"
    </button>
</div>

组件类:

product-inquiry-view.component.ts

export class ProductInquiryViewComponent implements OnInit, OnDestroy {
criteriaByStartDate: string;
criteriaByEndDate: string;
..........
findByCriteria() {
    criteriaByStartDate: Date;
    criteriaByEndDate: Date;
    let criteriaByStartDate = this.criteriaByStartDate;
    let criteriaByEndDate = this.criteriaByEndDate
    this.productInquiryViewService
        .query({
            'piDate.greaterThan': criteriaByStartDate,
            'piDate.lessThan': criteriaByEndDate,
            'piDocnum.contains': this.criteriaByDocnum
        }).subscribe(
        (res: HttpResponse<IProductInquiryView[]>) => {
            this.productInquiryViews = res.body;
        },
        (res: HttpErrorResponse) => this.onError(res.message)
    );
}

控制器:

产品查询视图资源.java

@GetMapping("/product-inquiry-views")
@Timed
public ResponseEntity<List<ProductInquiryViewDTO>> getAllProductInquiryViews(ProductInquiryViewCriteria criteria) {
    log.debug("REST request to get ProductInquiryViews by criteria: {}", criteria);
    List<ProductInquiryViewDTO> entityList = productInquiryViewQueryService.findByCriteria(criteria);
    return ResponseEntity.ok().body(entityList);
}

我得到了例外:

 2019-04-15 12:48:45.910  WARN 24330 --- [  XNIO-2 task-1] .m.m.a.ExceptionHandlerExceptionResolver : Resolved exception caused by handler execution: org.springframework.validation.BindException:
org.springframework.validation.BeanPropertyBindingResult: 2 errors
Field error in object 'productInquiryViewCriteria' on field 'piDate.greaterThan': rejected value [Mon Apr 01 2019 00:00:00 GMT 0300]; codes 
[typeMismatch.productInquiryViewCriteria.piDate.greaterThan,typeMismatch.piDate.greaterThan,typeMismatch.greaterThan,typeMismatch.java.time.ZonedDateTime,typeMismatch]; arguments
[org.springframework.context.support.DefaultMessageSourceResolvable: codes [productInquiryViewCriteria.piDate.greaterThan,piDate.greaterThan]; arguments [];
default message [piDate.greaterThan]]; default message [Failed to convert  property value of type 'java.lang.String' to required type 'java.time.ZonedDateTime' 
for property 'piDate.greaterThan'; nested exception is  org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] 
to type [java.time.ZonedDateTime] for value 'Mon Apr 01 2019  00:00:00 GMT 0300'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [Mon Apr 01 2019 00:00:00 GMT 0300]]   enter code here

我看到"周一 Apr 01 2019 00:00:00 GMT 0300"不是解析到 ZoneDateTime 的相应字符串,所以我尝试以这种格式发送条件:

"2019-04-01T00:15:30+03:00[Europe/Moscow]";

相同的结果。

应该是:

this.productInquiryViewService
        .query({
            'piDate.greaterThan': criteriaByStartDate.toISOString(),
            'piDate.lessThan': criteriaByEndDate.toISOString(),
...