Ad

MismatchException: Failed To Convert Value Of Type 'java.lang.String' To Required Type 'int'; Nested Exception Is Java.lang.NumberFormatException

- 1 answer

controller

///////////////////////////////////////////////////////////////////////// get
///////////////////////////////////////////////////////////////////////// employee
///////////////////////////////////////////////////////////////////////// no to
///////////////////////////////////////////////////////////////////////// update
@RequestMapping(value = "/editemp/{id}")
public String edit(@PathVariable int id, Model model) {
    model.addAttribute("employee", emloyeeService.findEmpById(id));
    return "empedit";
}

above code to edit employee data by id and it's working this is url http://localhost:9090/springwebjdbctemplate/editemp/2

@RequestMapping(path = "/getallemp", method = RequestMethod.POST)
public String edit(@Valid Employee employee, BindingResult bindingResult) {
    if (bindingResult.getErrorCount() > 0) {
        return "empedit";
    } else {
        emloyeeService.updateEmpData(employee);
        return "redirect:/allemp";
    }

exception occurs here when i try to store modified data and redirect the request to "allEmp.jsp" page this is url http://localhost:9090/springwebjdbctemplate/editemp/getallemp i think the problem in url it should be http://localhost:9090/springwebjdbctemplate/getallemp instead of above url

Ad

Answer

Your thinking is correct. Actually the first URL http://localhost:9090/springwebjdbctemplate/editemp/getallemp is being mapped to the first method and so it is trying to convert "getallemp" to an int. And so it is getting that exception. The second URL http://localhost:9090/springwebjdbctemplate/getallemp will be mapped to the second method correctly.

Ad
source: stackoverflow.com
Ad