当前位置:   article > 正文

(java毕业设计源码)基于java蛋糕甜品商店管理系统源码_javaweb网上蛋糕商城源码

javaweb网上蛋糕商城源码

基于java蛋糕甜品商店管理系统

项目获取请看文章最底下官网

蛋糕甜品商店管理系统是基于java编程语言和mysql数据开发的系统,系统主要分为用户和管理员两个角色,用户可以在线浏览蛋糕商品,商品分类信息,商品详情,下订单购买等功能;管理员对用户,商品,分类,订单进行管理。系统基于javaee运行jsp,ajax,servlet,mysql等技术。本设计难度适中,适合作为java毕业设计和java课程设计来参考和学习。


一.技术环境

JDK版本:1.8
IDE工具:eclipse
数据库: mysql 5.6
编程语言: Java
tomcat: 8.0
详细技术:HTML+CSS+JS+JSP+JAVA+Servlet+MYSQL


二.项目文件(项目获取请看文末官网)

在这里插入图片描述


三.系统功能

在这里插入图片描述


四.代码示例

package servlet.admin;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import  bean.Admin;
import  bean.PageBean;
import  dao.AdminDao;
import  dao.impl.AdminDaoImpl;
import  util.DateUtil;

import net.sf.json.JSONObject;

/**
 * Servlet implementation class UserServlet
 */
@WebServlet("/jsp/admin/AdminManageServlet")
public class AdminManageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static final String ADMINLIST_PATH="adminManage/adminList.jsp";//用户列表页面地址
	private static final String ADMINADD_PATH="adminManage/adminAdd.jsp";//用户增加页面地址
	private static final String ADMINEDIT_PATH="adminManage/adminEdit.jsp";//用户修改页面地址

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String action=request.getParameter("action");
		switch(action){
		case "list":
			adminList(request,response);
			break;
		case "add":
			adminAdd(request,response);
			break;
		case "update":
			adminUpdate(request,response);
			break;
		case "edit":
			adminEdit(request,response);
			break;
		case "del":
			adminDel(request,response);
			break;
		case "batDel":
			adminBatDel(request,response);
			break;
		case "find":
			adminFind(request,response);
			break;
		}

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
	
	//查询用户列表
	private void adminList(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		AdminDao ad=new AdminDaoImpl();
		int curPage=1;
		String page=request.getParameter("page");
		if(page!=null){
			curPage=Integer.parseInt(page);
		}
		//获取xml中设置的每页显示大小参数
		int maxSize=Integer.parseInt(request.getServletContext().getInitParameter("maxPageSize"));
		
		PageBean pageBean=new PageBean(curPage,maxSize,ad.cakeReadCount());
		
		request.setAttribute("adminList", ad.userList(pageBean));
		request.setAttribute("pageBean", pageBean);
		
		request.getRequestDispatcher(AdminManageServlet.ADMINLIST_PATH).forward(request, response);
		
	}
	
	//增加用户
	private void adminAdd(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		AdminDao ad=new AdminDaoImpl();
		Admin admin=new Admin(request.getParameter("userName"),request.getParameter("passWord"),
				request.getParameter("name"));
		//添加之前判断用户名是否在库中存在
		if(new AdminDaoImpl().findUser(admin.getUserName())){
			request.setAttribute("adminMessage", "用户添加失败!用户名已存在");
			request.getRequestDispatcher(AdminManageServlet.ADMINADD_PATH).forward(request, response);
		}else{
			//执行dao层添加操作
			if(ad.userAdd(admin)){
				request.setAttribute("adminMessage", "用户添加成功!");
				adminList(request, response);//通过servlet中listUser跳到用户列表
			}else{
				request.setAttribute("adminMessage", "用户添加失败!");
				request.getRequestDispatcher(AdminManageServlet.ADMINADD_PATH).forward(request, response);
			}
		}
		
	}
	//更新用户信息
	private void adminUpdate(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Admin admin=new Admin(Integer.parseInt(request.getParameter("id")),
				request.getParameter("passWord"),
				request.getParameter("name")
				);
		AdminDao ad=new AdminDaoImpl();
		if(ad.userUpdate(admin)) {
			request.setAttribute("adminMessage", "用户更新成功");
			adminList(request, response);//通过servlet中listUser跳到用户列表
		}else {
			//更新失败跳转到修改页面
			request.setAttribute("adminMessage", "用户更新失败");
			request.setAttribute("adminInfo", ad.findUser(Integer.valueOf(admin.getId())));//这里回去是Admin对象
			request.getRequestDispatcher(AdminManageServlet.ADMINEDIT_PATH).forward(request, response);
		}
		
	}

	//修改用户
	private void adminEdit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String id=request.getParameter("id");
		AdminDao ad=new AdminDaoImpl();
		request.setAttribute("adminInfo",ad.findUser(Integer.valueOf(id)));//这里回去是Admin对象
		request.getRequestDispatcher(AdminManageServlet.ADMINEDIT_PATH).forward(request, response);
	}
	
	//删除用户
	private void adminDel(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		int id=Integer.parseInt(request.getParameter("id"));
		AdminDao ad=new AdminDaoImpl();
		if(ad.delUser(id)) {
			request.setAttribute("adminMessage", "用户已删除");
		}else {
			request.setAttribute("adminMessage", "用户删除失败");
		}
		//用户删除成功失败都跳转到用户列表页面
		adminList(request, response);//通过servlet中listUser跳到用户列表
	}
	
	//批量删除
	private void adminBatDel(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		String ids=request.getParameter("ids");
		AdminDao ad=new AdminDaoImpl();
		
		if(ad.batDelUser(ids)) {
			request.setAttribute("adminMessage", "用户已批量删除");
		}else {
			request.setAttribute("adminMessage", "用户批量删除失败");
		}
		//用户删除成功失败都跳转到用户列表页面
		adminList(request, response);//通过servlet中listUser跳到用户列表
		
	}
	
	//ajax判断用户名(param为接收的用户名)
	private void adminFind(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String userName=request.getParameter("param");
		
		AdminDao ad=new AdminDaoImpl();
		//这里实例化json对象需要导入6个jar包(
		//commons-lang-2.4.jar ,commons-collections-3.2.1.jar,commons-beanutils-1.8.3.jar 
		//json-lib-2.4-jdk15.jar ,ezmorph-1.0.6.jar ,commons-logging-1.1.3.jar)
		JSONObject json=new JSONObject();
		if(ad.findUser(userName)){
			json.put("info", "用户名已存在");
			json.put("status", "n");
		}else{
			json.put("info", "用户名可以使用");
			json.put("status", "y");
		}
		response.getWriter().write(json.toString());
	}
	
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
package servlet.admin;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.IOUtils;

import  bean.Cake;
import  bean.Catalog;
import  bean.PageBean;
import  bean.UpLoadImg;
import  dao.CakeDao;
import  dao.CatalogDao;
import  dao.UpLoadImgDao;
import  dao.impl.CakeDaoImpl;
import  dao.impl.CatalogDaoImpl;
import  dao.impl.UpLoadImgDaoImpl;
import  util.RanUtil;

import net.sf.json.JSONObject;

/**
 * Servlet implementation class CakeManageServlet
 */
@WebServlet("/jsp/admin/CakeManageServlet")
public class CakeManageServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
	private static final String BOOKLIST_PATH = "cakeManage/cakeList.jsp";// 商品列表页面地址
	private static final String BOOKADD_PATH = "cakeManage/cakeAdd.jsp";// 商品增加页面地址
	private static final String BOOKEDIT_PATH = "cakeManage/cakeEdit.jsp";// 商品修改页面地址
	private static final String BOOKDETAIL_PATH = "cakeManage/cakeDetail.jsp";// 商品详情页面地址
	private static final String BOOKIMGDIR_PATH="images/cake/cakeimg/";//商品图片保存文件夹相对路径

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String action = request.getParameter("action");
		switch (action) {
		case "list":
			cakeList(request, response);
			break;
		case "detail":
			cakeDetail(request, response);
			break;
		case "addReq":
			cakeAddReq(request, response);
			break;
		case "add":
			cakeAdd(request, response);
			break;
		case "edit":
			cakeEdit(request, response);
			break;
		case "update":
			cakeUpdate(request,response);
			break;
		case "find":
			cakeFind(request, response);
			break;
		case "updateImg":
			updateImg(request,response);
			break;
		case "del":
			cakeDel(request,response);
			break;
		case "batDel":
			cakeBatDel(request,response);
			break;
		case "seach":
			seachCake(request,response);
		}
	}
	private void seachCake(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		int curPage = 1;
		String page = request.getParameter("page");
		if (page != null) {
			curPage = Integer.parseInt(page);
		}
		int maxSize = Integer.parseInt(request.getServletContext().getInitParameter("maxPageSize"));
		String cakename = request.getParameter("cakename");
		CakeDao bd = new CakeDaoImpl();
		PageBean pb = null;
		if(cakename != null && cakename != "") {
			pb = new PageBean(curPage, maxSize, bd.cakeReadCount(cakename));
			request.setAttribute("cakeList", bd.cakeList(pb,cakename));
		}else {
			pb = new PageBean(curPage, maxSize, bd.cakeReadCount());
			request.setAttribute("cakeList", bd.cakeList(pb));
		}
		
		request.setAttribute("pageBean", pb);
		request.getRequestDispatcher(BOOKLIST_PATH).forward(request, response);
	}

	//商品批量删除
	private void cakeBatDel(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String ids=request.getParameter("ids");
		CakeDao bd=new CakeDaoImpl();
		UpLoadImgDao uid=new UpLoadImgDaoImpl();
		File contextPath=new File(request.getServletContext().getRealPath("/"));
		
		String imgIds=bd.findimgIdByIds(ids);//批量查询图片的id并组成一组字符串
		
		List<UpLoadImg> list = uid.findImgByIds(imgIds);
		if(bd.cakeBatDelById(ids)) {
			request.setAttribute("cakeMessage", "商品已批量删除");
			if(uid.imgBatDelById(imgIds)) {
				for(UpLoadImg uli:list) {
					//批量删除本地文件
					File f=new File(contextPath,uli.getImgSrc());
					if(f.exists()) {
						f.delete();
					}
				}
			}
		}else {
			request.setAttribute("cakeMessage", "商品批量删除失败");
		}
		//用户删除成功失败都跳转到用户列表页面
		cakeList(request, response);//通过servlet中listUser跳到用户列表
	}

	//商品删除
	private void cakeDel(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int id=Integer.parseInt(request.getParameter("id"));
		File contextPath=new File(request.getServletContext().getRealPath("/"));
		CakeDao bd=new CakeDaoImpl();
		UpLoadImgDao uid=new UpLoadImgDaoImpl();
		Cake cake=bd.findCakeById(id);
		//这里先删除数据库商品信息,再删除商品图片及本地硬盘图片信息
		if(bd.cakeDelById(id)) {
			request.setAttribute("cakeMessage", "商品已删除");
			if(uid.imgDelById(cake.getImgId())) {
				//删除本地文件
				File f=new File(contextPath,cake.getUpLoadImg().getImgSrc());
				if(f.exists()) {
					f.delete();
				}
			}
		}else {
			request.setAttribute("cakeMessage", "商品删除失败");
		}
		
		//用户删除成功失败都跳转到用户列表页面
		cakeList(request, response);//通过servlet中listUser跳到用户列表
		
	}

	//商品更新
	private void cakeUpdate(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		CakeDao cakeDao=new CakeDaoImpl();
		Cake cake=new Cake();
		cake.setCakeId(Integer.parseInt(request.getParameter("cakeId")));
		cake.setCatalogId(Integer.parseInt(request.getParameter("catalog")));
		cake.setPrice(Double.parseDouble(request.getParameter("price")));
		cake.setDescription(request.getParameter("description"));
		
		if(cakeDao.cakeUpdate(cake)) {
			request.setAttribute("cakeMessage", "修改成功");
			cakeList(request, response);
		}else {
			request.setAttribute("cakeMessage", "图片失败");
			request.setAttribute("cakeInfo", cakeDao.findCakeById(cake.getCakeId()));
			request.getRequestDispatcher(BOOKEDIT_PATH).forward(request, response);
		}
	}

	// 更新商品图片
	private void updateImg(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		int cakeId = Integer.parseInt(request.getParameter("id"));
		boolean flag = false;
		String imgSrc = null;
		OutputStream outputStream = null;
		InputStream inputStream = null;
		String imgName = null;
		String contentType = null;

		CakeDao cakeDao = new CakeDaoImpl();
		UpLoadImgDao upImgDao = new UpLoadImgDaoImpl();
		
		File contextPath=new File(request.getServletContext().getRealPath("/"));
		File dirPath = new File( contextPath,BOOKIMGDIR_PATH);
		if (!dirPath.exists()) {
			dirPath.mkdirs();
		}

		DiskFileItemFactory dfif = new DiskFileItemFactory();
		ServletFileUpload servletFileUpload = new ServletFileUpload(dfif);
		List<FileItem> parseRequest = null;
		try {
			parseRequest = servletFileUpload.parseRequest(request);
		} catch (FileUploadException e) {
			e.printStackTrace();
		}
		Iterator<FileItem> iterator = parseRequest.iterator();
		while (iterator.hasNext()) {
			FileItem fileItem = iterator.next();
			if (!fileItem.isFormField()) {

				inputStream = fileItem.getInputStream();
				contentType = fileItem.getContentType();
				if ("image/jpeg".equals(contentType)) {
					imgName = RanUtil.getUUID() + ".jpg";
					flag = true;
				}
				if ("image/png".equals(contentType)) {
					imgName = RanUtil.getUUID() + ".png";
					flag = true;
				}

			}

		}
		if (flag) {
			imgSrc = BOOKIMGDIR_PATH + imgName;
			outputStream = new FileOutputStream(new File(contextPath,imgSrc));
			IOUtils.copy(inputStream, outputStream);
			outputStream.close();
			inputStream.close();
			//根据商品id去查询图片信息
			Cake cake = cakeDao.findCakeById(cakeId);
			UpLoadImg upImg = cake.getUpLoadImg();
			// 删除旧图片文件如果存在
			File oldImg = new File(contextPath,cake.getUpLoadImg().getImgSrc());
			if (oldImg.exists()) {
				oldImg.delete();
			}
			upImg.setImgName(imgName);
			upImg.setImgSrc(imgSrc);
			upImg.setImgType(contentType);
			
			
			if (upImgDao.imgUpdate(upImg)) {
				request.setAttribute("cakeMessage", "图片修改成功");
			} else {
				request.setAttribute("cakeMessage", "图片修改失败");
			}
		} else {
			request.setAttribute("cakeMessage", "图片修改失败");
		}
		cakeEdit(request,response);
	}

	// 获取商品分类信息
	private void cakeAddReq(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		CatalogDao cd = new CatalogDaoImpl();
		request.setAttribute("catalog", cd.getCatalog());
		request.getRequestDispatcher(BOOKADD_PATH).forward(request, response);

	}

	// 商品增加
	private void cakeAdd(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		boolean flag = false;
		
		Map<String, String> map = new HashMap<>();
		InputStream inputStream = null;
		OutputStream outputStream = null;
		File dirPath = new File(request.getServletContext().getRealPath("/") + BOOKIMGDIR_PATH);
		if (!dirPath.exists()) {
			dirPath.mkdirs();
		}

		DiskFileItemFactory dfif = new DiskFileItemFactory();
		ServletFileUpload servletFileUpload = new ServletFileUpload(dfif);
		// 解决乱码
		servletFileUpload.setHeaderEncoding("ISO8859_1");

		List<FileItem> parseRequest = null;
		try {
			parseRequest = servletFileUpload.parseRequest(request);
		} catch (FileUploadException e) {
			e.printStackTrace();
		}

		Iterator<FileItem> iterator = parseRequest.iterator();

		while (iterator.hasNext()) {
			FileItem fileItem = iterator.next();
			// 判断是否是表单的普通字段true为普通表单字段,false为上传文件内容
			if (fileItem.isFormField()) {
				String name = new String(fileItem.getFieldName().getBytes("ISO8859_1"), "utf-8");
				String value = new String(fileItem.getString().getBytes("ISO8859_1"), "utf-8");
				map.put(name, value);
			} else {
				String imgName = null;

				String contentType = fileItem.getContentType();

				if ("image/jpeg".equals(contentType)) {
					imgName = RanUtil.getUUID() + ".jpg";
					flag = true;
				}
				if ("image/png".equals(contentType)) {
					imgName = RanUtil.getUUID() + ".png";
					flag = true;
				}
				if (flag) {
					inputStream = fileItem.getInputStream();
					File file = new File(dirPath, imgName);
					outputStream = new FileOutputStream(file);
					// 保存img信息到map集合中,后面传入对象使用
					map.put("imgName", imgName);
					map.put("imgSrc", BOOKIMGDIR_PATH + imgName);
					map.put("imgType", contentType);
				}

			}
		}
		// 如果上传的内容小于3个必填项或者图片没有或类型不正确返回
		if (map.size() < 3 || !flag) {
			request.setAttribute("cakeMessage", "商品添加失败");
			cakeAddReq(request, response);
		} else {
			// 验证通过才可以保存图片流到本地
			IOUtils.copy(inputStream, outputStream);
			outputStream.close();
			inputStream.close();

			// 把map集合中存储的表单数据提取出来转换为cake对象
			// 这里要求商品增加的字段要和数据库字段一致,不然map集合转对象会出错
			Cake cake = new Cake();
			cake.setCakeName(map.get("cakeName"));
			cake.setPrice(Double.parseDouble(map.get("price")));
			cake.setDescription(map.get("desc"));
			
			// 商品分类信息
			Catalog catalog = cake.getCatalog();
			catalog.setCatalogId(Integer.parseInt(map.get("catalog")));
			// 图片信息
			UpLoadImg upLoadImg = cake.getUpLoadImg();
			upLoadImg.setImgName(map.get("imgName"));
			upLoadImg.setImgSrc(map.get("imgSrc"));
			upLoadImg.setImgType(map.get("imgType"));

			// 增加商品先增加商品图片,商品图片增加成功了在添加商品信息
			UpLoadImgDao uid = new UpLoadImgDaoImpl();
			if (uid.imgAdd(cake.getUpLoadImg())) {
				// 获取商品图片添加后的id
				Integer imgId = uid.findIdByImgName(upLoadImg.getImgName());
				upLoadImg.setImgId(imgId);

				CakeDao bd = new CakeDaoImpl();
				if (bd.cakeAdd(cake)) {
					request.setAttribute("cakeMessage", "商品添加成功");
					cakeList(request, response);
				} else {
					request.setAttribute("cakeMessage", "商品添加失败");
					cakeAddReq(request, response);
				}
			} else {
				// 图片添加失败就判定商品添加失败
				request.setAttribute("cakeMessage", "商品添加失败");
				cakeAddReq(request, response);
			}

		}
	}

	// 获取商品列表
	private void cakeList(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		int curPage = 1;
		String page = request.getParameter("page");
		if (page != null) {
			curPage = Integer.parseInt(page);
		}
		int maxSize = Integer.parseInt(request.getServletContext().getInitParameter("maxPageSize"));
		CakeDao bd = new CakeDaoImpl();
		PageBean pb = new PageBean(curPage, maxSize, bd.cakeReadCount());
		
		request.setAttribute("pageBean", pb);
		request.setAttribute("cakeList", bd.cakeList(pb));
		request.getRequestDispatcher(BOOKLIST_PATH).forward(request, response);
	}

	// 商品详情页
	private void cakeDetail(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String id = request.getParameter("id");
		CakeDao bd = new CakeDaoImpl();
		request.setAttribute("cakeInfo", bd.findCakeById(Integer.parseInt(id)));
		request.getRequestDispatcher(BOOKDETAIL_PATH).forward(request, response);

	}

	// 接收商品修改请求
	private void cakeEdit(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		int cakeId = Integer.parseInt(request.getParameter("id"));
		CakeDao cakeDao = new CakeDaoImpl();
		CatalogDao catalogDao = new CatalogDaoImpl();
		request.setAttribute("catalog", catalogDao.getCatalog());//获取商品分类信息
		request.setAttribute("cakeInfo", cakeDao.findCakeById(cakeId));//获取商品信息byId
		request.getRequestDispatcher(BOOKEDIT_PATH).forward(request, response);
	}

	// ajax查找商品是否存在
	private void cakeFind(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String cakeName = request.getParameter("param");

		CakeDao bd = new CakeDaoImpl();
		// 这里实例化json对象需要导入6个jar包(
		// commons-lang-2.4.jar
		// ,commons-collections-3.2.1.jar,commons-beanutils-1.8.3.jar
		// json-lib-2.4-jdk15.jar ,ezmorph-1.0.6.jar ,commons-logging-1.1.3.jar)
		JSONObject json = new JSONObject();
		if (bd.findCakeByCakeName(cakeName)) {
			json.put("info", "该商品已存在");
			json.put("status", "n");
		} else {
			json.put("info", "输入正确");
			json.put("status", "y");
		}
		response.getWriter().write(json.toString());

	}

}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
  • 344
  • 345
  • 346
  • 347
  • 348
  • 349
  • 350
  • 351
  • 352
  • 353
  • 354
  • 355
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • 363
  • 364
  • 365
  • 366
  • 367
  • 368
  • 369
  • 370
  • 371
  • 372
  • 373
  • 374
  • 375
  • 376
  • 377
  • 378
  • 379
  • 380
  • 381
  • 382
  • 383
  • 384
  • 385
  • 386
  • 387
  • 388
  • 389
  • 390
  • 391
  • 392
  • 393
  • 394
  • 395
  • 396
  • 397
  • 398
  • 399
  • 400
  • 401
  • 402
  • 403
  • 404
  • 405
  • 406
  • 407
  • 408
  • 409
  • 410
  • 411
  • 412
  • 413
  • 414
  • 415
  • 416
  • 417
  • 418
  • 419
  • 420
  • 421
  • 422
  • 423
  • 424
  • 425
  • 426
  • 427
  • 428
  • 429
  • 430
  • 431
  • 432
  • 433
  • 434
  • 435
  • 436
  • 437
  • 438
  • 439
  • 440
  • 441
  • 442
  • 443
  • 444
  • 445
  • 446
  • 447
  • 448
  • 449
  • 450
  • 451
  • 452
  • 453

五.项目截图

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/黑客灵魂/article/detail/767022
推荐阅读
相关标签
  

闽ICP备14008679号