0
I am unable to configure the classes convert in spring boot to convert the date that comes from the view into String to the controler that expects a Localdate java8, Someone could give me a hint ?
0
I am unable to configure the classes convert in spring boot to convert the date that comes from the view into String to the controler that expects a Localdate java8, Someone could give me a hint ?
1
I decided as follows:
@Component
@ConfigurationPropertiesBinding
public class LocalDateFormatter implements Converter<String, LocalDate> {
@Override
public LocalDate convert(String source) {
if(source==null){
return null;
}
return LocalDate.parse(source, DateTimeFormatter.ofPattern("dd/MM/yyyy"));
}
}
import java.text.ParseException;
import java.time.format.DateTimeFormatter;
import java.time.temporal.Temporal;
import java.util.Locale;
import org.springframework.format.Formatter;
public abstract class TemporalFormatter<T extends Temporal> implements Formatter<T> {
@Override
public String print(T temporal, Locale locale) {
DateTimeFormatter formatter = getDateTimeFormatter(locale);
return formatter.format(temporal);
}
@Override
public T parse(String text, Locale locale) throws ParseException {
DateTimeFormatter formatter = getDateTimeFormatter(locale);
return parse(text, formatter);
}
private DateTimeFormatter getDateTimeFormatter(Locale locale) {
return DateTimeFormatter.ofPattern(pattern(locale));
}
public abstract String pattern(Locale locale);
public abstract T parse(String text, DateTimeFormatter formatter);
}
Is that the solution or is it a supplementary code to the question?
Was the solution !!
Browser other questions tagged jpa spring thymeleaf
You are not signed in. Login or sign up in order to post.
What JPA implementation are you using? You can enter your code?
– Felipe Marinho
Friend I managed to solve
– Michael Thiago