🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
核心代码 web ~~~ //删除 public void deleteCategory(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { // 1 调用service中的查询方法 Map<String, String[]> parameterMap = request.getParameterMap(); Category category=new Category(); BeanUtils.populate(category,parameterMap); CategoryService service=new CategoryService(); boolean updateCategory = service.deleteCategory(category); if (updateCategory){ // 删除成功后重定向到生鲜列表界面 response.sendRedirect(request.getContextPath()+"/category?method=queryCategoryList&currentPage=1&currentCount=5"); }else { // 失败了直接提示 response.setContentType("text/html;charset=utf-8"); response.getWriter().write("删除失败"); } } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } ~~~ service ~~~ //删除 public boolean deleteCategory(Category category) throws SQLException { CategoryDao dao=new CategoryDao(); boolean updateCategory = dao.deleteCategory(category); return updateCategory; } ~~~ dao ~~~ //删除 public boolean deleteCategory(Category category) throws SQLException { ComboPooledDataSource dataSource=new ComboPooledDataSource(); QueryRunner queryRunner=new QueryRunner(dataSource); String sql="delete from category where c_id=?"; int row = queryRunner.update(sql,category.getC_id()); return row>0?true:false; } ~~~ UserServlet.java ~~~ //登录成功跳转生鲜种类列表界面 response.sendRedirect(request.getContextPath()+"/category?method=queryCategoryList"); ~~~ 前端 ~~~ <td> <a href="${pageContext.request.contextPath}/category?method=deleteCategory&c_id=${category.c_id}">删除</a> <a href="${pageContext.request.contextPath}/category-update.jsp?c_id=${category.c_id}&c_name=${category.c_name}&type=${category.type}&place=${category.place}">修改</a> </td> ~~~