产品操作-查询全部产品

编写jsp页面

请求发起页面 index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>主页</title>
</head>
<body>
	<a href="${pageContext.request.contextPath}/product/findAll.do">查询产品信息</a>
</body>
</html>

显示产品页面 product-list.jsp

Controller

@Controller
@RequestMapping("/product")
public class ProductController {

	@Autowired
	private IProductService productService;
	
	@RequestMapping("/findAll.do")
		public ModelAndView findAll() throws Exception {
		ModelAndView mv = new ModelAndView();
		List<Product> products = productService.findAll();
		mv.addObject("productList", products);
		mv.setViewName("product-list");
		return mv;
	}
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,这是一个比较简单的产品信息管理模块,可以使用C++中的类和对象来实现。下面是一个简单的实现,仅供参考: ```c++ #include <iostream> #include <string> #include <vector> using namespace std; // 产品信息类 class Product { public: string name; // 产品名称 string model; // 产品规格型号 string desc; // 产品描述 double price; // 产品价格 // 构造函数 Product() {} // 构造函数,用于快速初始化产品信息 Product(string name, string model, string desc, double price) { this->name = name; this->model = model; this->desc = desc; this->price = price; } // 显示产品信息 void display() { cout << "产品名称:" << name << endl; cout << "规格型号:" << model << endl; cout << "产品描述:" << desc << endl; cout << "产品价格:" << price << endl; } }; // 产品管理类 class ProductManager { private: vector<Product> products; // 产品列表 public: // 添加产品信息 void addProduct(Product product) { products.push_back(product); cout << "添加成功!" << endl; } // 修改产品信息 void modifyProduct(string name, string model, Product newProduct) { for (int i = 0; i < products.size(); i++) { if (products[i].name == name && products[i].model == model) { products[i] = newProduct; cout << "修改成功!" << endl; return; } } cout << "未找到该产品!" << endl; } // 删除产品信息 void deleteProduct(string name, string model) { for (int i = 0; i < products.size(); i++) { if (products[i].name == name && products[i].model == model) { products.erase(products.begin() + i); cout << "删除成功!" << endl; return; } } cout << "未找到该产品!" << endl; } // 查询所有产品信息 void queryAll() { if (products.size() == 0) { cout << "暂无产品信息!" << endl; return; } for (int i = 0; i < products.size(); i++) { cout << "===========" << endl; products[i].display(); } } // 按产品名称查询 void queryByName(string name) { vector<Product> result; for (int i = 0; i < products.size(); i++) { if (products[i].name == name) { result.push_back(products[i]); } } if (result.size() == 0) { cout << "未找到该产品!" << endl; return; } for (int i = 0; i < result.size(); i++) { cout << "===========" << endl; result[i].display(); } } // 按产品规格型号查询 void queryByModel(string model) { vector<Product> result; for (int i = 0; i < products.size(); i++) { if (products[i].model == model) { result.push_back(products[i]); } } if (result.size() == 0) { cout << "未找到该产品!" << endl; return; } for (int i = 0; i < result.size(); i++) { cout << "===========" << endl; result[i].display(); } } }; int main() { ProductManager manager; while (true) { cout << "请选择操作:1.添加产品信息 2.修改产品信息 3.删除产品信息 4.查询所有产品信息 5.按名称查询 6.按规格型号查询 0.退出" << endl; int choice; cin >> choice; if (choice == 0) { break; } else if (choice == 1) { cout << "请输入产品名称:"; string name; cin >> name; cout << "请输入产品规格型号:"; string model; cin >> model; cout << "请输入产品描述:"; string desc; cin >> desc; cout << "请输入产品价格:"; double price; cin >> price; Product product(name, model, desc, price); manager.addProduct(product); } else if (choice == 2) { cout << "请输入要修改的产品名称和规格型号:"; string name, model; cin >> name >> model; cout << "请输入新的产品信息:"; string newName, newModel, newDesc; double newPrice; cout << "请输入产品名称:"; cin >> newName; cout << "请输入产品规格型号:"; cin >> newModel; cout << "请输入产品描述:"; cin >> newDesc; cout << "请输入产品价格:"; cin >> newPrice; Product newProduct(newName, newModel, newDesc, newPrice); manager.modifyProduct(name, model, newProduct); } else if (choice == 3) { cout << "请输入要删除的产品名称和规格型号:"; string name, model; cin >> name >> model; manager.deleteProduct(name, model); } else if (choice == 4) { manager.queryAll(); } else if (choice == 5) { cout << "请输入要查询产品名称:"; string name; cin >> name; manager.queryByName(name); } else if (choice == 6) { cout << "请输入要查询产品规格型号:"; string model; cin >> model; manager.queryByModel(model); } else { cout << "无效操作!" << endl; } } return 0; } ``` 这个程序中,我们定义了一个 `Product` 类来表示产品信息,其中包含了产品名称、规格型号、描述和价格等属性。然后,我们又定义了一个 `ProductManager` 类来管理产品信息,其中包含了添加、修改、删除和查询等方法。 在 `main` 函数中,我们使用一个循环来不断读取用户的选择,然后调用对应的方法来处理。例如,当用户选择添加产品信息时,我们就会提示用户输入产品的各种属性,然后创建一个 `Product` 对象,并调用 `ProductManager` 的 `addProduct` 方法将其添加到产品列表中。其他操作也类似。 需要注意的是,这个程序还有一些不足之处,例如没有进行输入验证、没有进行异常处理等等。这些问题需要根据具体情况进行完善。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值