/api/test?page=-1&size=50&nextDateOfScreening.greaterThan=2020-04-03&sort=id,asc
这是我的传球网址,在控制器中,我收到的是。
@GetMapping("/test")
public ResponseEntity<List<ExampleDTO>> getAllTIBenScrDetails(ExampleCriteria criteria, Pageable pageable) {
Page<ExampleDTO> page = tIBenScrDetailsQueryService.findByCriteria(criteria, pageable);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(ServletUriComponentsBuilder.fromCurrentRequest(), page);
return ResponseEntity.ok().headers(headers).body(page.getContent());
}
和 例子标准 级别为:
public class ExampleCriteria implements Serializable, Criteria {
private LocalDateFilter nextDateOfScreening; //jhipster LocalDateFilter
}
而我收到的日期过滤器的不良请求为:。
Field error in object 'ExampleCriteria' on field 'nextDateOfScreening.greaterThan': rejected value [2020-04-03]; codes [typeMismatch.ExampleCriteria.nextDateOfScreening.greaterThan,typeMismatch.nextDateOfScreening.greaterThan,typeMismatch.greaterThan,typeMismatch.java.time.LocalDate,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [ExampleCriteria.nextDateOfScreening.greaterThan,nextDateOfScreening.greaterThan]; arguments []; default message [nextDateOfScreening.greaterThan]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.time.LocalDate' for property 'nextDateOfScreening.greaterThan'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.time.LocalDate] for value '2020-04-03'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2020-04-03]]
对于 大于等于 和 小于等于 坏的请求错误是没有得到,但对于 大于 和 小于 错误是有的。谁能帮我解决这个问题?
首先 greaterThanEquals
不存在于 LocalDateFilter
. 事实上,它是 greaterOrEqualThan
所以nextDateOfScreening.greaterOrEqualThan
.
这也是它 "工作 "的原因,因为弹簧没有找到。LocalDateFilter
设置器,因此创建了一个 "空 "的 LocalDateFilter
.
对于 lessThan
找到了设定器,但转换了 String
到 LocalDate
是没有配置的。为了解决这个问题,你必须声明一个自定义的转换器->。
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
@Component
public class LocalDateConverter implements Converter<String, LocalDate> {
@Override
public LocalDate convert(final String s) {
return LocalDate.parse(s, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
}
}