@WebServlet("/admin/goods/*")
public class GoodsServlet extends HttpServlet {
private GoodsService goodsService = new GoodsServiceImpl();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String uri = req.getRequestURI(); // 获取请求URI
String action = uri.substring(uri.lastIndexOf("/") + 1); // 获取操作指令
switch (action) {
case "list":
list(req, resp);
break;
case "toAdd":
toAdd(req, resp);
break;
case "add":
add(req, resp);
break;
case "toEdit":
toEdit(req, resp);
break;
case "edit":
edit(req, resp);
break;
case "del":
del(req, resp);
break;
default:
list(req, resp);
break;
}
}
private void list(HttpServletRequest req, HttpServletResponse resp) throws IOException {
List<Goods> goodsList = goodsService.listGoods();
req.setAttribute("goodsList", goodsList);
req.getRequestDispatcher("/admin/goods/list.jsp").forward(req, resp);
}
private void toAdd(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// 获取所有一级分类
List<Category> categoryList = CategoryService.listCategory();
req.setAttribute("categoryList", categoryList);
// 获取所有品牌
List<Brand> brandList = BrandService.listBrand();
req.setAttribute("brandList", brandList);
// 获取所有供应商
List<Provider> providerList = ProviderService.listProvider();
req.setAttribute("providerList", providerList);
// 获取所有单位
List<Unit> unitList = UnitService.listUnit();
req.setAttribute("unitList", unitList);
// 获取所有特征
List<Feature> featureList = FeatureService.listFeature();
req.setAttribute("featureList", featureList);
req.getRequestDispatcher("/admin/goods/add.jsp").forward(req, resp);
}
private void add(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String name = req.getParameter("name");
String categoryId = req.getParameter("categoryId");
String brandId = req.getPa
评论已关闭