Wpis z mikrobloga

#programowanie #java #spring
Mirki potrzebuję porady, chodzi o request z parametrami, czy ktoś może zerknąć czy zrobiłem to poprawnie? I jeszcze jedna sprawa, przy zapisywaniu daty korzystam z typu LocalDate, baza danych przechowuje to jako BLOB, dodaję kilka obiektów do bazy i chcę przetestować takiego requesta:

http://localhost:8080/reports/daily?startdate=2018-03-22&enddate=2018-03-24

Zwraca mi:
There was an unexpected error (type=Unsupported Media Type, status=415).
Content type 'null' not supported

Z tym, że nie mam żadnego nulla w DB także nie wiem za bardzo o co może chodzić. Kod tej metody: https://paste.ofcode.org/VpKLHcPqjBry8eSWqhAQTe
  • 10
@BigAngryPenguin: dobra to zmieniłem, teraz jeszcze pytanie co do daty, czy LocalDate jest w tym przypadku odpowiedni? Jest problem z konwersją daty mimo dodanych odpowiednich dependency:

""message": "Failed to convert value of type 'java.lang.String' to required type 'java.time.LocalDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@org.springframework.web.bind.annotation.RequestParam java.time.LocalDate] for value '2018-03-22';"
@kaervek: Tak ten sam błąd:

2018-05-31 15:40:29.623 WARN 11496 --- [nio-8080-exec-5] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to bind request element: org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.time.LocalDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@org.springframework.web.bind.annotation.RequestParam @org.springframework.format.annotation.DateTimeFormat java.time.LocalDate] for value '2018-03-22'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2018-03-22]
@Dominias: Ewidentnie ma problem z castowaniem stringa do localdate'a

zmień tego localdate z paramsów na Stringa bo RequestParam się to nie podoba i będzie działać

@RequestParam(value="startDate", required = false) String startDate){

DateTimeFormatter dateTimeFormat =
new DateTimeFormatter(DateTimeFormatter.BASICISODATE);

LocalDateTime date = dateTimeFormat.parse(startDate, LocalDateTime::from);
}

coś takiego