当前位置:   article > 正文

基于javaweb+mysql的ssm网上果蔬商城水果蔬菜商城系统(java+ssm+mysql+tomcat+jsp)

基于javaweb+mysql的ssm网上果蔬商城水果蔬菜商城系统(java+ssm+mysql+tomcat+jsp)

基于javaweb+mysql的ssm网上果蔬商城水果蔬菜商城系统(java+ssm+mysql+tomcat+jsp)

私信源码获取及调试交流

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb的SSM网上果蔬商城水果蔬菜商城系统(java+ssm+mysql+tomcat+jsp)

一、项目简述

功能: 功能:系统分管理员界面与用户界面 管理员:用户管理,商品类别管理,商品管理,订单管理,公 告管理留言里筲等 向户:房总主册功能,用户登录功能,商品浏览,商品留言评 论,商品购买,商品支付,订单查询等等

二、项目运行

环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)

项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + Fileupload + maven等等。

	 */
	@RequestMapping(value = "/findByObjJson", method = RequestMethod.POST)
	@ResponseBody
	public String findByObjByEntityJson(ItemCategory itemCategory, HttpServletRequest request, HttpServletResponse response) {
		//分页查询
		Pager<ItemCategory> pagers = itemCategoryService.findByEntity(itemCategory);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("pagers", pagers);
		jsonObject.put("obj", itemCategory);
		return jsonObject.toString();
	}
	
	  
	/**
	 * 分页查询 返回list json(通过Map)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/findByMapJson",  method = RequestMethod.POST)
	@ResponseBody
	public String findByMapJson(ItemCategory itemCategory,HttpServletRequest request, HttpServletResponse response) {
		//通过map查询
		Map<String,Object> params = new HashMap<String,Object>();
        if(!isEmpty(itemCategory.getName())){
        	params.put("name", itemCategory.getName());
		}
        if(!isEmpty(itemCategory.getPid())){
        	params.put("pid", itemCategory.getPid());
		}
        if(!isEmpty(itemCategory.getIsDelete())){
        	params.put("isDelete", itemCategory.getIsDelete());
		}
		//分页查询
		Pager<ItemCategory> pagers = itemCategoryService.findByMap(params);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("pagers", pagers);
		jsonObject.put("obj", itemCategory);
		return jsonObject.toString();
	}
	
	
	/**
	 * ajax 添加
  • 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
//		//3.通过参数删除
//     //通过map查询
//		Map<String,Object> params = new HashMap<String,Object>();
//		
//        if(!isEmpty(sc.getItemId())){
//        	params.put("itemId", sc.getItemId());
//		}
//       
//        if(!isEmpty(sc.getUserId())){
//        	params.put("userId", sc.getUserId());
//		}
//       
//		scService.deleteByMap(params);
//		//4.状态删除
//		Sc load = scService.getById(sc.getId())
//		load.setIsDelete(1);
//		scService.update(load);
		//5.状态删除
		//Sc load = scService.load(id);
		//load.setIsDelete(1);
		//scService.update(load);
		return "redirect:/sc/findBySql.action";
	}
	
	// --------------------------------------- 华丽分割线 ------------------------------
	// --------------------------------------- 【下面是ajax操作的方法。】 ------------------------------

	/*********************************查询列表【不分页】***********************************************/
	
	/**
	 * 【不分页 => 查询列表 => 无条件】
	* @Title: listAll 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listAllJson", method = RequestMethod.POST)
	@ResponseBody
	public String listAllJson(Sc sc, HttpServletRequest request, HttpServletResponse response){
		List<Sc> listAll = scService.listAll();
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("list", listAll);
		jsonObject.put("obj", sc);
		return jsonObject.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
		}
        if(!isEmpty(address.getArea())){
        	sql += " and area like '%"+address.getArea()+"%'";
		}
        if(!isEmpty(address.getBm())){
        	sql += " and bm like '%"+address.getBm()+"%'";
		}
        if(!isEmpty(address.getIsUse())){
        	sql += " and isUse like '%"+address.getIsUse()+"%'";
		}
       sql += " ORDER BY ID DESC ";
		Pager<Address> pagers = addressService.findBySqlRerturnEntity(sql);
		model.addAttribute("pagers", pagers);
		//存储查询条件
		model.addAttribute("obj", address);
		return "address/address";
	}
	
	
	
	@RequestMapping(value = "/my")
	public String my(Address address, Model model, HttpServletRequest request, HttpServletResponse response) {
		//分页查询
		Object attribute = request.getSession().getAttribute("userId");
		if (attribute == null){
			return "redirect:/login/uLogin";
		}
		JSONObject js = new JSONObject();
		Integer userId = Integer.valueOf(attribute.toString());
		String sql = "SELECT * FROM address WHERE 1=1 and userId = "+userId;
        if(!isEmpty(address.getName())){
        	sql += " and name like '%"+address.getName()+"%'";
		}
        if(!isEmpty(address.getPhone())){
        	sql += " and phone like '%"+address.getPhone()+"%'";
		}
        if(!isEmpty(address.getArea())){
        	sql += " and area like '%"+address.getArea()+"%'";
		}
        if(!isEmpty(address.getBm())){
        	sql += " and bm like '%"+address.getBm()+"%'";
		}
        if(!isEmpty(address.getIsUse())){
        	sql += " and isUse like '%"+address.getIsUse()+"%'";
		}
       sql += " ORDER BY ID DESC ";
		Pager<Address> pagers = addressService.findBySqlRerturnEntity(sql);
		model.addAttribute("pagers", pagers);
		//存储查询条件
		model.addAttribute("obj", address);
		return "address/my";
	}
	
	/**
  • 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
	@RequestMapping(value = "/listAll")
	public String listAll(Address address, Model model, HttpServletRequest request, HttpServletResponse response){
		List<Address> listAll = addressService.listAll();
		model.addAttribute("list", listAll);
		return "address/address";
	}
	
	/**
	 *  【不分页=》查询列表=>有条件】
	* @Title: listByEntity 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listByEntity")
	public String listByEntity(Address address, Model model, HttpServletRequest request, HttpServletResponse response){
		List<Address> listAll = addressService.listAllByEntity(address);
		model.addAttribute("list", listAll);
		return "address/address";
	}
	
	/**
	 *  【不分页=》查询列表=>有条件】
	* @Title: listByMap 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listByMap")
	public String listByMap(Address address, Model model, HttpServletRequest request, HttpServletResponse response){
		//通过map查询
		Map<String,Object> params = new HashMap<String,Object>();
	        if(!isEmpty(address.getName())){
	        	params.put("name", address.getName());
			}
	        if(!isEmpty(address.getPhone())){
	        	params.put("phone", address.getPhone());
			}
	        if(!isEmpty(address.getArea())){
	        	params.put("area", address.getArea());
			}
	        if(!isEmpty(address.getBm())){
	        	params.put("bm", address.getBm());
			}
	        if(!isEmpty(address.getIsUse())){
	        	params.put("isUse", address.getIsUse());
			}
	    List<Address> listAll = addressService.listByMap(params);
		model.addAttribute("list", listAll);
  • 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
		jsonObject.put("list", listAll);
		jsonObject.put("obj", sc);
		return jsonObject.toString();
	}
	
	/**
	 *  【不分页=》查询列表=>有条件】
	* @Title: listByEntity 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listByEntityJson", method = RequestMethod.POST)
	@ResponseBody
	public String listByEntityJson(Sc sc,  HttpServletRequest request, HttpServletResponse response){
		List<Sc> listAll = scService.listAllByEntity(sc);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("list", listAll);
		jsonObject.put("obj", sc);
		return jsonObject.toString();
	}
	
	/**
	 *  【不分页=》查询列表=>有条件】
	* @Title: listByMap 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listByMapJson", method = RequestMethod.POST)
	@ResponseBody
	public String listByMapJson(Sc sc,HttpServletRequest request, HttpServletResponse response){
		//通过map查询
		Map<String,Object> params = new HashMap<String,Object>();
	        if(!isEmpty(sc.getItemId())){
	        	params.put("itemId", sc.getItemId());
			}
	        if(!isEmpty(sc.getUserId())){
	        	params.put("userId", sc.getUserId());
			}
	    List<Sc> listAll = scService.listByMap(params);
	    JSONObject jsonObject = new JSONObject();
		jsonObject.put("list", listAll);
		jsonObject.put("obj", sc);
		return jsonObject.toString();
	}
	
	
	/**
	 * 分页查询 返回list json(通过对象)
  • 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
	* @param @return 设定文件 
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listByMap")
	public String listByMap(Item item, Model model, HttpServletRequest request, HttpServletResponse response){
		//通过map查询
		Map<String,Object> params = new HashMap<String,Object>();
	        if(!isEmpty(item.getName())){
	        	params.put("name", item.getName());
			}
	        if(!isEmpty(item.getPrice())){
	        	params.put("price", item.getPrice());
			}
	        if(!isEmpty(item.getScNum())){
	        	params.put("scNum", item.getScNum());
			}
	        if(!isEmpty(item.getGmNum())){
	        	params.put("gmNum", item.getGmNum());
			}
	        if(!isEmpty(item.getUrl1())){
	        	params.put("url1", item.getUrl1());
			}
	        if(!isEmpty(item.getUrl2())){
	        	params.put("url2", item.getUrl2());
			}
	        if(!isEmpty(item.getUrl3())){
	        	params.put("url3", item.getUrl3());
			}
	        if(!isEmpty(item.getUrl4())){
	        	params.put("url4", item.getUrl4());
			}
	        if(!isEmpty(item.getUrl5())){
	        	params.put("url5", item.getUrl5());
			}
	        if(!isEmpty(item.getMs())){
	        	params.put("ms", item.getMs());
			}
	        if(!isEmpty(item.getPam1())){
	        	params.put("pam1", item.getPam1());
			}
	        if(!isEmpty(item.getPam2())){
	        	params.put("pam2", item.getPam2());
			}
	        if(!isEmpty(item.getPam3())){
  • 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
	
	@RequestMapping(value = "/my")
	public String my(ItemOrder itemOrder, Model model, HttpServletRequest request, HttpServletResponse response) {
		//分页查询
		Object attribute = request.getSession().getAttribute("userId");
		if (attribute == null){
			return "redirect:/login/uLogin";
		}
		JSONObject js = new JSONObject();
		Integer userId = Integer.valueOf(attribute.toString());
		String sql = "SELECT * FROM item_order WHERE 1=1 and user_id="+userId;
        sql += " ORDER BY ID DESC ";
		
      //  0.新建待发货1.已取消 2已已发货3.到收货
        
		List<ItemOrder> all = itemOrderService.listBySqlReturnEntity(sql);
		
		String sql2 = "SELECT * FROM item_order WHERE status = 0 and user_id="+userId;
        sql2 += " ORDER BY ID DESC ";
		
        //待发货
        List<ItemOrder> dfh = itemOrderService.listBySqlReturnEntity(sql2);
        
    	String sql3 = "SELECT * FROM item_order WHERE status = 1 and user_id="+userId;
        sql3 += " ORDER BY ID DESC ";
        
        //已取消
        List<ItemOrder> yqx = itemOrderService.listBySqlReturnEntity(sql3);
        
        
    	String sql4 = "SELECT * FROM item_order WHERE status = 2 and user_id="+userId;
        sql4 += " ORDER BY ID DESC ";
        
        //已发货
        List<ItemOrder> yfh = itemOrderService.listBySqlReturnEntity(sql4);
        
        
    	String sql5 = "SELECT * FROM item_order WHERE status = 3 and user_id="+userId;
        sql5 += " ORDER BY ID DESC ";
        
        //待评价
        List<ItemOrder> dpj = itemOrderService.listBySqlReturnEntity(sql5);
        
		model.addAttribute("all", all);
  • 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
		/*以下是多种删除方式*/
//		//2.通过实体条件删除
//		scService.deleteByEntity(sc);
//		//3.通过参数删除
//     //通过map查询
//		Map<String,Object> params = new HashMap<String,Object>();
//		
//        if(!isEmpty(sc.getItemId())){
//        	params.put("itemId", sc.getItemId());
//		}
//       
//        if(!isEmpty(sc.getUserId())){
//        	params.put("userId", sc.getUserId());
//		}
//       
//		scService.deleteByMap(params);
//		//4.状态删除
//		Sc load = scService.getById(sc.getId())
//		load.setIsDelete(1);
//		scService.update(load);
		//5.状态删除
		//Sc load = scService.load(id);
		//load.setIsDelete(1);
		//scService.update(load);
		return "redirect:/sc/findBySql.action";
	}
	
	// --------------------------------------- 华丽分割线 ------------------------------
	// --------------------------------------- 【下面是ajax操作的方法。】 ------------------------------

	/*********************************查询列表【不分页】***********************************************/
	
	/**
	 * 【不分页 => 查询列表 => 无条件】
	* @Title: listAll 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @return String 返回类型 
	* @throws
  • 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
//        if(!isEmpty(itemOrder.getCode())){
//        	params.put("code", itemOrder.getCode());
//		}
//       
//        if(!isEmpty(itemOrder.getAddTime())){
//        	params.put("addTime", itemOrder.getAddTime());
//		}
//       
//        if(!isEmpty(itemOrder.getTotal())){
//        	params.put("total", itemOrder.getTotal());
//		}
//       
//        if(!isEmpty(itemOrder.getIsDelete())){
//        	params.put("isDelete", itemOrder.getIsDelete());
//		}
//       
//        if(!isEmpty(itemOrder.getStatus())){
//        	params.put("status", itemOrder.getStatus());
//		}
//       
//		itemOrderService.deleteByMap(params);
//		//4.状态删除
//		ItemOrder load = itemOrderService.getById(itemOrder.getId())
//		load.setIsDelete(1);
//		itemOrderService.updateById(load);
		//5.状态删除
		//ItemOrder load = itemOrderService.load(id);
		//load.setIsDelete(1);
		//itemOrderService.updateById(load);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("message", "删除成功");
		return jsonObject.toString();
	}
	/**
	 * 单文件上传
	 * @param file
	 * @param request
	 * @param model
	 * @return
	 */
    @RequestMapping(value = "/saveFile")  
  • 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
        if(!isEmpty(item.getPam3())){
        	sql += " and pam3 like '%"+item.getPam3()+"%'";
		}
        if(!isEmpty(item.getType())){
        	sql += " and type like '%"+item.getType()+"%'";
		}
        if(!isEmpty(item.getIsDelete())){
        	sql += " and isDelete like '%"+item.getIsDelete()+"%'";
		}
       sql += " ORDER BY ID DESC ";
		Pager<Item> pagers = itemService.findBySqlRerturnEntity(sql);
		model.addAttribute("pagers", pagers);
		//存储查询条件
		model.addAttribute("obj", item);
		return "item/item";
	}
	
	
	/**
	 * 用户端查询列表
	 * @param item
	 * @param model
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/shoplist")
	public String shoplist(Item item,String condition, Model model, HttpServletRequest request, HttpServletResponse response) {
		
		//当二级分类为空,并且condition 为空的时候,不做查询
		/*if (StringUtils.isEmpty(condition) && item.getCategoryIdTwo() == null){
			return "redirect:/login/uIndex.action";
		}*/
		
		//直接点击类型过来的
		 //直接冲数据库查询
			String sql = "SELECT * FROM item WHERE 1=1 and isDelete =0 " ;
			  if(!isEmpty(item.getCategoryIdTwo())){
		        	sql += " and category_id_two= "+item.getCategoryIdTwo();
				}
			
			  if(!isEmpty(condition)){
		        	sql += " and name like '%"+condition+"%'";
				}
			if (!StringUtils.isEmpty(item.getPrice())){
				sql += " ORDER BY (price+0) DESC";
			}
			if (item.getGmNum() != null){
				sql += " ORDER BY gmNum DESC";
			}
  • 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
	 * @param 
	 * @return
	 */
	@RequestMapping(value = "/exAddJson", method = RequestMethod.POST)
	@ResponseBody
	public String exAddJson(Sc sc, Model model, HttpServletRequest request, HttpServletResponse response) {
		scService.insert(sc);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("message", "添加成功");
		return jsonObject.toString();
	}
	

	/**
	 * ajax 修改
	 * @param 
	 * @return
	 */
	@RequestMapping(value = "/exUpdate.json", method = RequestMethod.POST)
	@ResponseBody
	public String exUpdateJson(Sc sc, Model model, HttpServletRequest request, HttpServletResponse response) {
		//1.通过实体类修改,可以多传修改条件
		scService.updateById(sc);
		//2.通过主键id修改
		//scService.updateById(sc);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("message", "修改成功");
		return jsonObject.toString();
	}

	/**
	 * ajax 删除
	 * @return
	 */
	@RequestMapping(value = "/delete.json", method = RequestMethod.POST)
	@ResponseBody
	public String exDeleteJson(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
		///1.通过主键删除
		scService.deleteById(id);
		/*以下是多种删除方式*/
//		//2.通过实体条件删除
//		scService.deleteByEntity(sc);
//		//3.通过参数删除
//        //通过map查询
  • 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
		model.addAttribute("obj", user);
		return "user/user";
	}
	
	/**********************************【增删改】******************************************************/
	
	/**
	 * 跳至添加页面
	 * @return
	 */
	@RequestMapping(value = "/add")
	public String add() {
		return "user/add";
	}

	/**
	 * 跳至详情页面
	 * @return
	 */
	@RequestMapping(value = "/view")
	public String view(Model model,HttpServletRequest request) {
		Object attribute = request.getSession().getAttribute("userId");
		if (attribute == null){
			return "redirect:/login/uLogin";
		}
		JSONObject js = new JSONObject();
		Integer userId = Integer.valueOf(attribute.toString());
		User obj = userService.load(userId);
		model.addAttribute("obj",obj);
		return "user/view";
	}
	
	/**
	 * 添加执行
	 * @return
	 */
	@RequestMapping(value = "/exAdd")
	public String exAdd(User user, Model model, HttpServletRequest request, HttpServletResponse response) {
		userService.insert(user);
		return "redirect:/user/findBySql.action";
	}
	
	
  • 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
	 * @return
	 */
	@RequestMapping(value = "/add")
	public String add() {
		return "car/add";
	}

	/**
	 * 跳至详情页面
	 * @return
	 */
	@RequestMapping(value = "/view")
	public String view(Model model,HttpServletRequest request,String code) {
		Object attribute = request.getSession().getAttribute("userId");
		if (attribute == null){
			return "redirect:/login/uLogin";
		}
		Integer userId = Integer.valueOf(attribute.toString());
		
		model.addAttribute("code", code);
		return "car/view";
	}
	
	/**
	 * 添加执行
	 * @return
	 */
	@RequestMapping(value = "/exAdd")
	@ResponseBody
	public String exAdd(Car car, Model model, HttpServletRequest request, HttpServletResponse response) {
		Object attribute = request.getSession().getAttribute("userId");
		JSONObject js = new JSONObject();
		if (attribute == null){
			js.put("res", 0);
			return js.toJSONString();
		}
		Integer userId = Integer.valueOf(attribute.toString());
		car.setUserId(userId);
		Item load = itemService.load(car.getItemId());
		String price = load.getPrice();
		Double valueOf = Double.valueOf(price);
		car.setPrice(valueOf);
		if (load.getZk() != null){
			valueOf = (valueOf*load.getZk())/10;
			 BigDecimal bg = new BigDecimal(valueOf).setScale(2, RoundingMode.UP);
			car.setPrice(bg.doubleValue());
  • 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
	}
	
	/**
	 * 添加修改
	 * @return
	 * @throws IOException 
	 * @throws IllegalStateException 
	 */
	@RequestMapping(value = "/exUpdate")
	public String exUpdate(Item item, Model model, @RequestParam("file") CommonsMultipartFile[] files, HttpServletRequest request, HttpServletResponse response) throws IllegalStateException, IOException {
		//1.通过实体类修改,可以多传修改条件
		ItemCategory byId = itemCategoryService.getById(item.getCategoryIdTwo());
		item.setCategoryIdOne(byId.getPid());
		
		if (files.length > 0){
			 // 0 1 2 3 4
			for (int s = 0;s < files.length;s++){
				 System.out.println("开始");  
		          long  startTime=System.currentTimeMillis();
		          System.out.println("fileName:"+files[s].getOriginalFilename());
		          String n = UUIDUtils.create();
		          String path="D:/my/upload/"+n+files[s].getOriginalFilename();
		          System.out.println("===================================================");
		           System.out.println(path);
		          File newFile=new File(path);
		          //通过CommonsMultipartFile的方法直接写文件(注意这个时候)
		          files[s].transferTo(newFile);
		          long  endTime=System.currentTimeMillis();
		          System.out.println("方法二的运行时间:"+String.valueOf(endTime-startTime)+"ms");
		         System.out.println("*********************************************************");
		         System.out.println("*********************************************************");
		         
		         if (s == 0){
		        	 item.setUrl1("\\upload\\"+n+files[s].getOriginalFilename());
		         }
		         if (s == 1){
		        	 item.setUrl2("\\upload\\"+n+files[s].getOriginalFilename());
		         }
		         if (s == 2){
		        	 item.setUrl3("\\upload\\"+n+files[s].getOriginalFilename());
		         }
		         if (s == 3){
		        	 item.setUrl4("\\upload\\"+n+files[s].getOriginalFilename());
		         }
		         if (s == 4){
		        	 item.setUrl5("\\upload\\"+n+files[s].getOriginalFilename());
		         }
  • 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
			}
			
			int length = user_item.length;
			
			userItemLength.put(user_item[0], length);//eg: A 3
			userID.put(user_item[0], a);//用户ID与稀疏矩阵建立对应关系
			idUser.put(a, user_item[0]);
			//建立物品--用户倒排表
			for(int j = 1; j < length; j ++){
				if(items.contains(user_item[j])){//如果已经包含对应的物品--用户映射,直接添加对应的用户
					Set<String> set2 = itemUserCollection.get(user_item[j]);
					if (!CollectionUtils.isEmpty(set2)){
						set2.add(user_item[0]);
					}else{
						itemUserCollection.put(user_item[j], new HashSet<String>());//创建物品--用户倒排关系
						itemUserCollection.get(user_item[j]).add(user_item[0]);
					}
					//itemUserCollection.get(user_item[j]).add(user_item[0]);
				}else{//否则创建对应物品--用户集合映射
					items.add(user_item[j]);
					itemUserCollection.put(user_item[j], new HashSet<String>());//创建物品--用户倒排关系
					itemUserCollection.get(user_item[j]).add(user_item[0]);
				}
			}
			a++;	
		}
		
		System.out.println(itemUserCollection.toString());
		//计算相似度矩阵【稀疏】
		Set<Entry<String, Set<String>>> entrySet = itemUserCollection.entrySet();
		Iterator<Entry<String, Set<String>>> iterator = entrySet.iterator();
		while(iterator.hasNext()){
			Set<String> commonUsers = iterator.next().getValue();
			for (String user_u : commonUsers) {
				for (String user_v : commonUsers) {
					if(user_u.equals(user_v)){
						continue;
					}
					sparseMatrix[userID.get(user_u)][userID.get(user_v)] += 1;//计算用户u与用户v都有正反馈的物品总数
				}
  • 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
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listByMapJson", method = RequestMethod.POST)
	@ResponseBody
	public String listByMapJson(Item item,HttpServletRequest request, HttpServletResponse response){
		//通过map查询
		Map<String,Object> params = new HashMap<String,Object>();
	        if(!isEmpty(item.getName())){
	        	params.put("name", item.getName());
			}
	        if(!isEmpty(item.getPrice())){
	        	params.put("price", item.getPrice());
			}
	        if(!isEmpty(item.getScNum())){
	        	params.put("scNum", item.getScNum());
			}
	        if(!isEmpty(item.getGmNum())){
	        	params.put("gmNum", item.getGmNum());
			}
	        if(!isEmpty(item.getUrl1())){
	        	params.put("url1", item.getUrl1());
			}
	        if(!isEmpty(item.getUrl2())){
	        	params.put("url2", item.getUrl2());
			}
	        if(!isEmpty(item.getUrl3())){
	        	params.put("url3", item.getUrl3());
			}
	        if(!isEmpty(item.getUrl4())){
	        	params.put("url4", item.getUrl4());
			}
	        if(!isEmpty(item.getUrl5())){
	        	params.put("url5", item.getUrl5());
			}
	        if(!isEmpty(item.getMs())){
	        	params.put("ms", item.getMs());
			}
	        if(!isEmpty(item.getPam1())){
	        	params.put("pam1", item.getPam1());
			}
	        if(!isEmpty(item.getPam2())){
	        	params.put("pam2", item.getPam2());
  • 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
//       
//		orderDetailService.deleteByMap(params);
//		//4.状态删除
//		OrderDetail load = orderDetailService.getById(orderDetail.getId())
//		load.setIsDelete(1);
//		orderDetailService.updateById(load);
		//5.状态删除
		//OrderDetail load = orderDetailService.load(id);
		//load.setIsDelete(1);
		//orderDetailService.updateById(load);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("message", "删除成功");
		return jsonObject.toString();
	}
	/**
	 * 单文件上传
	 * @param file
	 * @param request
	 * @param model
	 * @return
	 */
    @RequestMapping(value = "/saveFile")  
    public String saveFile(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletRequest request, Model model) {  
  
        System.out.println("开始");  
        String path = request.getSession().getServletContext().getRealPath("/upload");  
        String fileName = file.getOriginalFilename();  
        System.out.println(path);  
        File targetFile = new File(path, fileName);  
        if(!targetFile.exists()){  
            targetFile.mkdirs();  
        }  
        //保存  
        try {  
            file.transferTo(targetFile);  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
  
        return "";  
    }  
  • 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
	 */
	@RequestMapping(value = "/listAllJson", method = RequestMethod.POST)
	@ResponseBody
	public String listAllJson(OrderDetail orderDetail, HttpServletRequest request, HttpServletResponse response){
		List<OrderDetail> listAll = orderDetailService.listAll();
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("list", listAll);
		jsonObject.put("obj", orderDetail);
		return jsonObject.toString();
	}
	
	/**
	 *  【不分页=》查询列表=>有条件】
	* @Title: listByEntity 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listByEntityJson", method = RequestMethod.POST)
	@ResponseBody
	public String listByEntityJson(OrderDetail orderDetail,  HttpServletRequest request, HttpServletResponse response){
		List<OrderDetail> listAll = orderDetailService.listAllByEntity(orderDetail);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("list", listAll);
		jsonObject.put("obj", orderDetail);
		return jsonObject.toString();
	}
	
	/**
	 *  【不分页=》查询列表=>有条件】
	* @Title: listByMap 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listByMapJson", method = RequestMethod.POST)
	@ResponseBody
	public String listByMapJson(OrderDetail orderDetail,HttpServletRequest request, HttpServletResponse response){
		//通过map查询
		Map<String,Object> params = new HashMap<String,Object>();
	        if(!isEmpty(orderDetail.getItemId())){
	        	params.put("itemId", orderDetail.getItemId());
			}
	        if(!isEmpty(orderDetail.getOrderId())){
	        	params.put("orderId", orderDetail.getOrderId());
			}
	        if(!isEmpty(orderDetail.getStatus())){
	        	params.put("status", orderDetail.getStatus());
			}
	    List<OrderDetail> listAll = orderDetailService.listByMap(params);
  • 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

请添加图片描述
请添加图片描述

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

闽ICP备14008679号