Answer the question
In order to leave comments, you need to log in
Spring MVC, how should forms with date be handled?
Good time!
I'm writing a project on Spring MVC, stuck on date parsing. There is a form on the front, for example:
Data is read from it to the controller, in the controller it is written to the database (via dao) using Hibernate. I can’t figure out how to parse the date, because a string is passed, but Date is stored. Explain on your fingers, please, how to do this and what happens in this case, or poke at a suitable example. Examples looked different, understanding did not come. Thank you.
UPD: In general, I will be glad for any information on the interaction of the front with the back, I swim in this topic.
Answer the question
In order to leave comments, you need to log in
As I understand it, you made the date input in the form of 3 fields ... Usually, they make one field and hang a js lib for date input on this field, for example JQuery Datepicker , and in the controller they do everything that azerphoenix wrote above
https://gerrytan.wordpress.com/2013/05/21/binding-...
I'm learning Spring MVC myself and haven't encountered submitting a Date from a form yet, but check out the link above.
As I understand it, you have @Entity and you need to specify the annotation - @DateTimeFormat Code
example:
@DateTimeFormat(pattern = "dd/MM/yyyy")
private Date dob;
public String addCustomer(@ModelAttribute("addCustomerForm") AddCustomerForm form) {
// do something with form input ..
}
input{type="date"}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question