Answer the question
In order to leave comments, you need to log in
When I send a POST request, I get a Bad request. Problem with converting date to string. How to decide?
There are such fields in the form
<div class="form-group">
<label class="labelForm" for="formBirthDay">Birth day</label>
<input type="date" class="form-control" th:field="*{birthDate}" id="formBirthDay" placeholder="Birth day">
</div>
@RequestMapping(value = "/signUp", method = RequestMethod.POST)
public void regCustomer(@ModelAttribute Customer customer) {
logger.debug("customer " + customer.toString);
}
@Configuration
public class DateTimeConfig {
@Bean
public FormattingConversionService formattingConversionService() {
DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService(false);
DateTimeFormatterRegistrar dateTimeFormatterRegistrar = new DateTimeFormatterRegistrar();
dateTimeFormatterRegistrar.setDateFormatter(DateTimeFormatter.ofPattern("dd.MM.yyyy"));
dateTimeFormatterRegistrar.setDateTimeFormatter(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss"));
dateTimeFormatterRegistrar.registerFormatters(conversionService);
return conversionService;
}
}
Answer the question
In order to leave comments, you need to log in
I solved the issue by adding an annotation to the @DateTimeFormat(pattern = "yyyy-MM-dd") bean class. I
haven't found another solution yet...(
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question