I’ve got a form on thymeleaf, that contains many type=date inputs. I need to get those dates on PostMapping. Sometimes it came with null value and compiler gives error
“required request parameter ‘date_smth’ for method parameter type Date is present but converted to null”
For dates I’m using Java.util.Date Now I’m trying to use formatter in RequestParam
@RequestParam(“date_smth_form”) @DateTimeFormat(iso=DateTimeFormat.ISO.DATE) Date date_smth
In my Entity I didn’t apply any configuration for this date columns, just:
Private Date date_smth
If u want to ask me, why u need formatter at all? I want my date to be yyyy.MM.dd format always, without any time data or utc data, just date.
Thank to you all ( ) , using of LocalDate solve all my problems, but also want to add that I use @Nullable to my LocalDate variables on @PostMapping in @RequestParam. Before, I don’t want to use LocalDate, because someone, who writes code before me already use Java.sql.Date everywhere, in all repositories, in all entities, in all services, in all controllers. But I gathered my strength and rewrote everything under localDate. Also, for me, I needed to convert LocalDate values to String on @GetMapping, don’t know, if it’s ok or not, but it’s works fine.