删除功能实现,对应controller类中的代码如下所示:
@RequestMapping(value="/{username}/delete",method=RequestMethod.GET) public String delete(@PathVariable String username) { users.remove(username); return "redirect:/user/users"; }
在列表页面添加删除某条数据的链接,对应添加如下代码:
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>用户列表</title> </head> <body> <a href="add">添加</a> <c:forEach items="${users}" var="um" > <a href="${um.value.username}">${um.value.username }</a> ----${um.value.nickname } ----${um.value.password }--<a href="${um.value.username }/update">修改</a> ----${um.value.email } <a href="${um.value.username }/delete">删除</a><br/> </c:forEach> </body> </html>
原文:http://www.cnblogs.com/birdman-oscar/p/4324925.html