SpringMVC entry (four) a simple user management example - CRUD

Recommended for you: Get network issues from WhatsUp Gold. Not end users.
Here to write about how to handle a single user information through the REST format.

1 access to personal information
1.1 in the Controller accession:
	//{username}Is the path variable- path parameters
	public String show(@PathVariable String username,Model model){ //@PathVariable refers to the use of path value as a parameter, there is{username}
		return "user/show";

1.2 in the WEB-INF/jsp/user directory to create JSP file show.jsp

1.3 to modify the list.jsp file, adding link information
---<a href="user/${um.value.username}">${um.value.nickname}</a>

The 2 update personal information
2.1 added in Controller:
	public String update(@PathVariable String username,Model model){
		return "user/update";
	public String update(@Validated User user,@PathVariable String username, BindingResult result){
		//Here if the database, according to the username to get the object, and then update the database. 
		users.put(username, user);
		return "redirect:/user/users";

2.2 add update.jsp referenced above, path.
	 	<sf:form method="post" modelAttribute="user">
   		User name: <sf:input path="username"/><sf:errors path="username"/><br/>
   		The user password: <sf:input path="password"/><sf:errors path="password"/><br/>
   		Nickname: <sf:input path="nickname"/> <br/>
   		The user's mailbox: <sf:input path="email"/><sf:errors path="email"/><br/>
   		 <input type="submit" value="Modify user"/>

2.3 in the list.jsp to add modify user link
---<a href="user/${um.value.username}/update">Modify</a>

3 delete user

3.1 added in Controller:
	public String delete(@PathVariable String username){
		return "redirect:/user/users";

3.2 in the list.jsp to add delete link.
---<a href="user/${um.value.username}/delete">Delete</a>

This crud completed.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Beatrix at December 09, 2013 - 10:58 PM