MethodArgumentTypeMismatchException in Spring Boot… here is a solution to the problem.
MethodArgumentTypeMismatchException in Spring Boot
I tried to remove the user by getting the id in the url by mistake:
Failed to convert value of type 'java.lang.String' to required type 'int';
nested exception is java.lang.NumberFormatException: For input string:
I changed int id to String id, but deleteMyUser()
won’t work because it accepts an integer.
Code:
<a href="/delete-user?id=${user.id}">x</a>
@RequestMapping("/delete-user{id}")
public String deleteUser(@PathVariable("id") int id,HttpServletRequest request)
{
request.setAttribute("mode","MODE_HOME");
userService.deleteMyUser(id);
return "welcome";
}
Solution
You should add id
to path, so remove ?id=
:
<a href="/delete-user${user.id}">x</a>