将下列代码修改为封装对象形式:public void goodsAdd(HttpServletRequest req, HttpServletResponse res) { //根据商品信息保存到数据库 int catelog_id = Integer.parseInt(req.getParameter("catelog_id")); String bianhao = req.getParameter("bianhao"); String mingcheng = req.getParameter("mingcheng"); String jieshao = req.getParameter("jieshao"); String pinpai = req.getParameter("pinpai"); String fujian = req.getParameter("fujian"); int jiage = Integer.parseInt(req.getParameter("jiage")); int kucun = 0; String del = "no"; String sql = "insert into t_goods(catelog_id,bianhao,mingcheng,jieshao,pinpai,fujian,jiage,kucun,del) " + "values(?,?,?,?,?,?,?,?,?)"; Object[] params = { catelog_id, bianhao, mingcheng, jieshao, pinpai, fujian, jiage, kucun, del }; DB mydb = new DB(); mydb.doPstm(sql, params); mydb.closed(); req.setAttribute("message", "操作成功"); req.setAttribute("path", "goods?type=goodsMana"); String targetURL = "/common/success.jsp"; dispatch(targetURL, req, res); }
时间: 2024-04-19 13:28:36 浏览: 24
public void goodsAdd(HttpServletRequest req, HttpServletResponse res) {
// 创建 Goods 对象并设置属性值
Goods goods = new Goods();
goods.setCatelogId(Integer.parseInt(req.getParameter("catelog_id")));
goods.setBianhao(req.getParameter("bianhao"));
goods.setMingcheng(req.getParameter("mingcheng"));
goods.setJieshao(req.getParameter("jieshao"));
goods.setPinpai(req.getParameter("pinpai"));
goods.setFujian(req.getParameter("fujian"));
goods.setJiage(Integer.parseInt(req.getParameter("jiage")));
goods.setKucun(0);
goods.setDel("no");
// 将 Goods 对象插入数据库
String sql = "insert into t_goods(catelog_id,bianhao,mingcheng,jieshao,pinpai,fujian,jiage,kucun,del) "
+ "values(?,?,?,?,?,?,?,?,?)";
Object[] params = {goods.getCatelogId(), goods.getBianhao(), goods.getMingcheng(), goods.getJieshao(), goods.getPinpai(),
goods.getFujian(), goods.getJiage(), goods.getKucun(), goods.getDel()};
DB mydb = new DB();
mydb.doPstm(sql, params);
mydb.closed();
req.setAttribute("message", "操作成功");
req.setAttribute("path", "goods?type=goodsMana");
String targetURL = "/common/success.jsp";
dispatch(targetURL, req, res);
}
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)