🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
核心代码 web ~~~ //修改 public void updateCategory(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.updateCategory(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 updateCategory(Category category) throws SQLException { CategoryDao dao=new CategoryDao(); boolean updateCategory = dao.updateCategory(category); return updateCategory; } ~~~ dao ~~~ //更新 public boolean updateCategory(Category category) throws SQLException { ComboPooledDataSource dataSource=new ComboPooledDataSource(); QueryRunner queryRunner=new QueryRunner(dataSource); String sql="update category set c_name=?,place=?,type=? where c_id=?"; int row = queryRunner.update(sql, category.getC_name(), category.getPlace(), category.getType(),category.getC_id()); if (row>0){ return true; }else { return false; } } ~~~ 前端 ~~~ <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> ~~~ ![](https://box.kancloud.cn/a0fe6a8cbf80b99ddd2cea3f700d4f8a_791x505.png) 结果 ![](https://box.kancloud.cn/e6f05f6791974c56f6906ba65eacc8cc_1092x547.png)