Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MethodArgumentTypeMismatchException in spring boot

I try to delete a user by getting id in url with an error:

Failed to convert value of type 'java.lang.String' to required type 'int'; 
nested exception is java.lang.NumberFormatException: For input string:

I change int id to String id, but then deleteMyUser() will not 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";

    }
like image 391
K.Nehe Avatar asked Nov 18 '25 16:11

K.Nehe


1 Answers

You should add the id to path, so remove ?id=:

<a href="/delete-user${user.id}">x</a>
like image 186
user7294900 Avatar answered Nov 20 '25 05:11

user7294900



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!