jHipster:搜索条件“ GreaterThan,LessThan”作为日期时间

时间:2019-04-15 10:22:28

标签: java angular typescript jhipster

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

product-inquiry-view.component.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)
    );
}

控制器:

ProductInquiryViewResource.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

我看到“ Mon Apr 01 2019 00:00:00 GMT 0300”不是用于解析到ZoneDateTime的字符串,所以我尝试以这种格式发送条件:

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

结果相同。

1 个答案:

答案 0 :(得分:0)

应该是:

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