删除功能_代码实现
package hf.xueqiang.web.servlet; import hf.xueqiang.service.UserService; import hf.xueqiang.service.impl.UserServiceImpl; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.annotation.*; import java.io.IOException; @WebServlet("/delUserServlet") public class DelUserServlet extends HttpServlet { @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //1.获取id String id = request.getParameter("id"); //2.调用service删除 UserService service = new UserServiceImpl(); service.deleteUser(id); //3.跳转到查询所有Servlet response.sendRedirect(request.getContextPath()+"/userListServlet"); } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request, response); } }
/** * 根据id删除数据 * @param id */ void deleteUser(String id); }
@Override public void deleteUser(String id) { dao.deleteUser(Integer.parseInt(id)); }
void deleteUser(int i); }
@Override public void deleteUser(int id) { //1.定义sql String sql = "delete from user where id = ?"; //2.执行sql template.update(sql, id); }
删除之前的:
删除之后的:
修改功能_分析
标签:功能,service,删除,void,request,deleteUser,id,import,代码 From: https://www.cnblogs.com/x3449/p/17117811.html