V
V
vincent_gun2018-11-07 00:48:24
MySQL
vincent_gun, 2018-11-07 00:48:24

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:
5be20b18ac95e072738380.png
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

2 answer(s)
E
Evhen, 2018-11-07
@EugeneP2

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

O
Orkhan Hasanli, 2018-11-07
@azerphoenix

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 ..
}

Or here, another example - https://stackoverflow.com/questions/43786382/submi...
to get data from a form withinput{type="date"}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question