java - How to pass ID to controller? -
i have form
<form method="post" action="/user/${id}"> <input type="text" name="id" value="${id}" placeholder="input id"> <button>get user</button> </form>
how pass id controller?
@requestmapping (value = "/user/{id}", method = requestmethod.post) public string getstudent(@pathvariable ("id") integer id, model model){ user saveduser = userrepository.get(id); model.addattribute("user", saveduser); return "user"; }
you way , consider passing ${id}
value through query string
<a href="user?id=${id}">get user</a>
and in controller,
@requestmapping ("user") public string getstudent(@requestparam integer id, model model){ user saveduser = userrepository.get(id); model.addattribute("user", saveduser); return "user"; }
hope helps !
Comments
Post a Comment