⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bookinfoaction.java

📁 java开发购物车+网上书城
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			    	}
			    	if("textarea".equals(fileItem.getFieldName()))
			    	{
			    		text=fileItem.getString("UTF-8");
			    	}
			    	if("select".equals(fileItem.getFieldName()))
			    	{
			    		picture=fileItem.getString("UTF-8");
			    	}
//			    	if("index".equals(fileItem.getFieldName()))
//			    	{
//			    		flag=fileItem.getString("gbk");
//			    	}
			    //+ new String(fileItem.getString().getBytes("iso8859-1"), "gbk"));
			    }else{
			     System.out.println(fileItem.getFieldName() + "   " + 
			        fileItem.getName() + "   " + 
			        fileItem.isInMemory() + "    " + 
			        fileItem.getContentType() + "   " + 
			        fileItem.getSize());

					if (fileItem.getName() != null && fileItem.getSize() != 0) {
						File fullFile = new File(fileItem.getName());
						 String path=TomCatVO.getTomCatPath();
					      path=path+"/picture/upload/";
					      System.out.println(path);
						String fileName=fullFile.getName();
					    String suffix=fileName.substring(fileName.indexOf("."));
					    //自动生成图片的名称
					    picturePath=System.currentTimeMillis()+suffix;
					    //图片的完全路径
					    picture+=path+picturePath;
						File newFile = new File(path+picturePath);
						try {
							fileItem.write(newFile);
						} catch (Exception e) {
							e.printStackTrace();
						}
					} else {
						System.out.println("文件没有选择 或 文件内容为空");
					}
				}
			}
		}
		
		BookInfoVo vo=new BookInfoVo();
		vo.setBookName(name);
		vo.setBookAuthor(author);
		vo.setBookPublish(publish);
		vo.setBookPrice(Double.parseDouble(prices));
		vo.setBookDiscount(Double.parseDouble(discount));
		vo.setShelfId(Integer.parseInt(content));
		vo.setBookShow(Integer.parseInt(show));
		vo.setBookContent(text);
		vo.setBookImgPath(picture);
		
		int i= bd.saveBook(vo);
		if(i>0){
			return new ActionForward("/background/addbook.jsp");
		}
//		String index=flag;
//		BookInfoDAO bidao=new BookInfoDAO();
//		bidao.editPictureOfBookByBookId(bookId, picturePath);
//		BookInfoVO bivo=new BookInfoVO();
//		bivo=bidao.getBookById(bookId);
//		request.setAttribute("index", index);
//		request.setAttribute("book", bivo);
//		return new ActionForward("/bookInfo.jsp");
		return null;
	}
	
	/**
	 * 修改图书时根据bookId查询图书信息
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward findBookInfoByBookId(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String bookId= request.getParameter("bookId");
		BookInfoVo vo= (BookInfoVo) bd.findBookInfoByBookId(Integer.parseInt(bookId));
		request.setAttribute("bookInfo", vo);
		List list= bd.findTwoContent();
		request.setAttribute("twoContent", list);
		return new ActionForward("/background/merchandiseInformationModify.jsp");
	}
	/**
	 * 修改图书信息
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward editBookInfo(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String bookId="";
		String name="";
		String author="";
		String publish="";
		String prices="";
		String discount="";
		String clickCount="";
		String content="";
		String text="";
		String show="";
        String picturePath="";
        String picture="";
		request.setCharacterEncoding("UTF-8");
		RequestContext requestContext = new ServletRequestContext(request);
		if (FileUpload.isMultipartContent(requestContext)) {
			DiskFileItemFactory factory = new DiskFileItemFactory();
			factory.setRepository(new File(TomCatVO.getTomCatPath()+"/picture/buffer/"));
			ServletFileUpload upload = new ServletFileUpload(factory);
			 upload.setSizeMax(2000000);
			List items = new ArrayList();
			try {
				items = upload.parseRequest(request);
			} catch (FileUploadException e1) {
				e1.printStackTrace();
				System.out.println("文件上传发生错误" + e1.getMessage());
			}
			for (int i=0;i<items.size();i++){
			    FileItem fileItem = (FileItem) items.get(i);
			    if(fileItem.isFormField()){
			    	if("bookId".equals(fileItem.getFieldName()))
			    	{
			    		bookId=fileItem.getString("UTF-8");
			    	}
			    	if("bookName".equals(fileItem.getFieldName()))
			    	{
			    		//文本框里面的值
			    		name=fileItem.getString("UTF-8");
			    	}
			    	if("bookAuthor".equals(fileItem.getFieldName()))
			    	{
			    		author=fileItem.getString("UTF-8");
			    	}
			    	if("bookPublish".equals(fileItem.getFieldName()))
			    	{
			    		publish=fileItem.getString("UTF-8");
			    	}
			    	if("prices".equals(fileItem.getFieldName()))
			    	{
			    		prices=fileItem.getString("UTF-8");
			    	}
			    	if("bookDiscount".equals(fileItem.getFieldName()))
			    	{
			    		discount=fileItem.getString("UTF-8");
			    	}
			    	if("clickCount".equals(fileItem.getFieldName()))
			    	{
			    		clickCount=fileItem.getString("UTF-8");
			    	}
			    	if("twoContent".equals(fileItem.getFieldName()))
			    	{
			    		content=fileItem.getString("UTF-8");
			    	}
			    	if("textarea".equals(fileItem.getFieldName()))
			    	{
			    		text=fileItem.getString("UTF-8");
			    	}
			    	if("show".equals(fileItem.getFieldName()))
			    	{
			    		show=fileItem.getString("UTF-8");
			    	}
			    	if("select".equals(fileItem.getFieldName()))
			    	{
			    		picture=fileItem.getString("UTF-8");
			    	}
			    }else{
			     System.out.println(fileItem.getFieldName() + "   " + 
			        fileItem.getName() + "   " + 
			        fileItem.isInMemory() + "    " + 
			        fileItem.getContentType() + "   " + 
			        fileItem.getSize());

					if (fileItem.getName() != null && fileItem.getSize() != 0) {
						File fullFile = new File(fileItem.getName());
						 String path=TomCatVO.getTomCatPath();
					      path=path+"/picture/upload/";
					      System.out.println(path);
						String fileName=fullFile.getName();
					    String suffix=fileName.substring(fileName.indexOf("."));
					    //自动生成图片的名称
					    picturePath=System.currentTimeMillis()+suffix;
					    //图片的完全路径
					    picture+=path+picturePath;
						File newFile = new File(path+picturePath);
						try {
							fileItem.write(newFile);
						} catch (Exception e) {
							e.printStackTrace();
						}
					} else {
						System.out.println("文件没有选择 或 文件内容为空");
					}
				}
			}
		}
		
		BookInfoVo vo=new BookInfoVo();
		vo.setBookId(Integer.parseInt(bookId));
		vo.setBookName(name);
		vo.setBookAuthor(author);
		vo.setBookPublish(publish);
		vo.setBookPrice(Double.parseDouble(prices));
		vo.setBookDiscount(Double.parseDouble(discount));
		vo.setShelfId(Integer.parseInt(content));
		vo.setBookContent(text);
		vo.setBookImgPath(picture);
		vo.setClickCount(Integer.parseInt(clickCount));
		vo.setBookShow(Integer.parseInt(show));
		int i= bd.editBook(vo);
		if(i>0){
			return new ActionForward("/background/editbook.jsp");
		}
//		String index=flag;
//		BookInfoDAO bidao=new BookInfoDAO();
//		bidao.editPictureOfBookByBookId(bookId, picturePath);
//		BookInfoVO bivo=new BookInfoVO();
//		bivo=bidao.getBookById(bookId);
//		request.setAttribute("index", index);
//		request.setAttribute("book", bivo);
//		return new ActionForward("/bookInfo.jsp");
		return null;
	}
	
	/**
	 * 查找所有已上架的图书
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward findComBook(HttpServletRequest request, HttpServletResponse response) throws Exception {
		List list= bd.findAllUp();
		request.setAttribute("list_up", list);
		return new ActionForward("/background/allUpBookInfo.jsp");
	}
	/**
	 * 添加推荐图书
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward comBookInfo(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String bookId= request.getParameter("bookId");
		List list= bd.findBookType(Integer.parseInt(bookId));
		if(list!=null){//代表推荐表中已经有了这本书,不能在让推荐
			bd.removeBookType(Integer.parseInt(bookId));
		}
		
		BookInfoVo vo= (BookInfoVo) bd.findBookInfoByBookId(Integer.parseInt(bookId));
		String bookName= vo.getBookName();
		BookInfoVo bv=new  BookInfoVo();
		bv.setBookId(Integer.parseInt(bookId));
		bv.setBookName(bookName);
		int i= bd.saveBookType(vo);
		if(i>0){
			return new ActionForward("/comm.do");
		}
		return null;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -