Home > Back-end >  How to get Date input value from thymeleaf to MySQL in Spring Boot Application Java?
How to get Date input value from thymeleaf to MySQL in Spring Boot Application Java?

Time:01-05

I want to get input value from Spring Boot Application thymeleaf(HTML) to MySQL Database in format Date. But I get this error message : "Failed to convert value of type 'java.lang.String' to required type 'java.sql.Date'".

This is my Controller path code below. Thanks in advance.

@GetMapping("/saveApplication")
    public String saveApplication(@RequestParam(name="name", required = false) String name,
            @RequestParam(name="surname", required = false) String surname,
            @RequestParam(name="place", required = false) String place,
            @RequestParam(name="start", required = false) @DateTimeFormat(pattern = "dd.MM.yyyy") Date start,
            @RequestParam(name="end", required = false) @DateTimeFormat(pattern = "dd.MM.yyyy") Date end,
            @RequestParam(name="identity", required = false) Integer identity,
            @RequestParam(name="tel", required = false) Integer tel,
            Model model) 
    {

        final Integer id = 1;
        
        
        String sql = "INSERT INTO `user`.`application` (`kullaniciid`, `name`, `surname`, `place`,`start`, `end`,`identity`,`tel`) VALUES ( ?, ?, ?,  ?, ?, ?, ?, ?)";
        
        jdbcTemplate.update(sql, id,name, surname, place,start, end,identity,tel);
        
        
        return "screen3";
    }

CodePudding user response:

Thank you for all. I fixed it change @DateTimeFormat to @Date and import Date.

  •  Tags:  
  • Related