💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
核心代码 web ~~~ //查询 public void queryCategoryList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 1 调用service中的查询方法 try { CategoryService service=new CategoryService(); List<Category> categoryList = service.queryCategory(); if ( categoryList!=null&&categoryList.size()>0) { request.setAttribute("list",categoryList); request.getRequestDispatcher("/category-list.jsp").forward(request,response); } else { request.getRequestDispatcher("/category-list.jsp").forward(request,response); } } catch (SQLException e) { e.printStackTrace(); } } ~~~ service ~~~ //查询 public List<Category> queryCategory() throws SQLException { CategoryDao dao = new CategoryDao(); List<Category> categories = dao.queryCategory(); return categories; } ~~~ dao ~~~ //查询 public List<Category> queryCategory() throws SQLException { ComboPooledDataSource dataSource=new ComboPooledDataSource(); QueryRunner queryRunner=new QueryRunner(dataSource); String sql="select * from category"; List<Category> categoryList = queryRunner.query(sql, new BeanListHandler<Category>(Category.class)); return categoryList; } ~~~ UserServlet.java ~~~ //登录成功跳转生鲜种类列表界面 response.sendRedirect(request.getContextPath()+"/category?method=queryCategoryList"); ~~~ 前端 ~~~ <a href="${pageContext.request.contextPath}/category?method=queryCategoryList" class="list-group-item text-center active">生鲜列表</a> <a href="${pageContext.request.contextPath}/category-add.jsp" class="list-group-item text-center ">新增生鲜</a> ~~~ 结果 ![](https://box.kancloud.cn/0b8701fa3746df90ea2faf5132589bdc_1499x791.png)