I work in Intellij IDEA, I create an entity in which I write the field
@Data @Entity public class Product { @Id @GeneratedValue(strategy = GenerationType.AUTO ) private int id; private String type; private String name; private String description; private int count; private double price; private Date date; I write this in the controller
@PostMapping public String add(@RequestParam String type, @RequestParam String name, @RequestParam String description, @RequestParam int count, @RequestParam double price, @RequestParam String date, Map<String, Object> model) throws ParseException { SimpleDateFormat format = new SimpleDateFormat(); format.applyPattern("yyyy-MM-dd"); Product product = new Product(type, name, description, count, price, format.parse(date)); productRepos.save(product); Iterable<Product> all = productRepos.findAll(); model.put("product", all); return "main"; } in the frontend write down so:
<input type="date" name="date" > When choosing a date on the frontend, it turns out like this: 2018-06-10 and in the database it is written in this form: 2018-06-10 15: 15: 25.0 Can someone tell me please, maybe somehow you can write the date differently and does not soak with the conversion ... tried to enter LocalDate instead of Date, then when adding a date from the frontend, I get an error ..