jHipster: критерии поиска "GreaterThan, LessThan" для даты и времени - PullRequest
0 голосов
/ 15 апреля 2019

В моем проекте jHipster я хочу найти строку по диапазону даты и времени.Фрагменты моего кода:

product-query-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-query-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

Я вижу, что «Пн Апр 01 2019 00:00:00 GMT 0300» не является строкой для разборав ZoneDateTime, поэтому я попытался отправить критерии в таком формате:

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

Тот же результат.

1 Ответ

0 голосов
/ 15 апреля 2019

Должно быть:

this.productInquiryViewService
        .query({
            'piDate.greaterThan': criteriaByStartDate.toISOString(),
            'piDate.lessThan': criteriaByEndDate.toISOString(),
...
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...