开发者学堂课程【Java Web项目实战2:图书商城:后台分类管理之修改分类】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/35/detail/797
后台分类管理之修改分类
内容介绍:
一、修改分为两类
二、加载分类相关步骤
三、修改分类相关步骤
四、加载分类相关代码
五、修改分类相关代码
l 修改分为两类:
1、加载分类
2、修改分类
l 加载分类相关步骤
list.jsp(修改连接)→AdminCategoryServle#editPre()
Ø 获取 cid,通过 cid 来调用 service方法,得到 Category 对象。
Ø 保存到 request 域中,转发到 edit.jsp里。
Ø 所有的页面都在 category 里,然后找到 mod.jsp
Mod.jsp:把当前的 Category 对象显示到表单中
l 修改分类相关步骤
修改分类:mod.jsp(提交表单)→
AdminCategoryServle#edit()
Ø 封装表单数据。
Ø 调用 service方法完成修改工作。
Ø 调用 findAII()
l 加载分类相关代码
修改之前的加载工作:
public String editPre (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String cid = request.getParameter("cid");
request.setAttribute("category",categoryservice.load(cid));
return "f:/adminjsps/admin/category/mod.jsp";
}
加载分类
public Category load(string cid) {
returncategoryDao.load(cid);
}
加载分类
public Category load(String cid) {
try {
String sql = "select* from category where cid=?";
return qr.query(sql,new
BeanHandler(Category.class),cid);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
l 修改分类相关代码
修改分类:
1、封装表单数据
2、调用 service 方法完成修改工作。
3、调用 findAII
public String edit (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
category category = CommonUtils.toBean(request.getParameterMap(),Category.class);
Categoryservice.edit(category);
return findAll (request, response);
}
修改分类
public void edit(Category category) {
try {
stringsql = "update category set cname=? where cid=?";
qr.update(sql,category.getCname(),category.getcid());
} catch (SQLException e) {
thrownew RuntimeException(e);
}
}