源码获取:俺的博客首页 "资源" 里下载!

项目介绍


本项目分为前后台,分为管理员与普通用户两种角色,管理员登录后台,普通用户登录前台;

管理员角色:

查看客户信息,酒水管理,查看类目,订单管理等功能。

用户角色包含以下功能:

用户登录与注册,修改个人信息,查看首页,查看酒水分类,查看热销酒水,查看酒水详情,查看购物车,确认收货信息,查看用户订单等功能。


环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 
5.数据库:MySql 5.7版本;
6.是否Maven项目:否;


技术栈

JSP+CSS+jQuery+bootstrap+mysql+servlet


使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中src/utils/DBUtil.java配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/jsp_baijiu_shop/ 登录 注:tomcat中配置项目路径必须为jsp_baijiu_shop,否则会有异常;
用户账号/密码:user/123456
管理员账号/密码:admin/admin

 

 

 

 

 

用户管理控制层:

@Controller
@RequestMapping("/user")
public class UserController extends BaseController {
	
	
	/**
	 * 依赖注入 start dao/service/===
	 */
	@Autowired
	private UserService userService;
	
	// --------------------------------------- 华丽分割线 ------------------------------
	
	/*********************************查询列表【不分页】***********************************************/
	
	/**
	 * 【不分页 => 查询列表 => 无条件】
	* @Title: listAll 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @author
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listAll")
	public String listAll(User user, Model model, HttpServletRequest request, HttpServletResponse response){
		List<User> listAll = userService.listAll();
		model.addAttribute("list", listAll);
		return "user/user";
	}
	
	/**
	 *  【不分页=》查询列表=>有条件】
	* @Title: listByEntity 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @author
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listByEntity")
	public String listByEntity(User user, Model model, HttpServletRequest request, HttpServletResponse response){
		List<User> listAll = userService.listAllByEntity(user);
		model.addAttribute("list", listAll);
		return "user/user";
	}
	
	/**
	 *  【不分页=》查询列表=>有条件】
	* @Title: listByMap 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @author 
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listByMap")
	public String listByMap(User user, Model model, HttpServletRequest request, HttpServletResponse response){
		//通过map查询
		Map<String,Object> params = new HashMap<String,Object>();
	        if(!isEmpty(user.getUserName())){
	        	params.put("userName", user.getUserName());
			}
	        if(!isEmpty(user.getPassWord())){
	        	params.put("passWord", user.getPassWord());
			}
	        if(!isEmpty(user.getPhone())){
	        	params.put("phone", user.getPhone());
			}
	        if(!isEmpty(user.getRealName())){
	        	params.put("realName", user.getRealName());
			}
	        if(!isEmpty(user.getSex())){
	        	params.put("sex", user.getSex());
			}
	        if(!isEmpty(user.getAddress())){
	        	params.put("address", user.getAddress());
			}
	        if(!isEmpty(user.getEmail())){
	        	params.put("email", user.getEmail());
			}
	    List<User> listAll = userService.listByMap(params);
		model.addAttribute("list", listAll);
		return "user/user";
	}
	
	
	/*********************************查询列表【分页】***********************************************/
	
	
	
	/**
	 * 分页查询 返回list对象(通过对象)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/findByObj")
	public String findByObj(User user, Model model, HttpServletRequest request, HttpServletResponse response) {
		//分页查询
		Pager<User> pagers = userService.findByEntity(user);
		model.addAttribute("pagers", pagers);
		//存储查询条件
		model.addAttribute("obj", user);
		return "user/user";
	}
	
	/**
	 * 分页查询 返回list对象(通过对By Sql)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/findBySql")
	public String findBySql(User user, Model model, HttpServletRequest request, HttpServletResponse response) {
		//分页查询
		String sql = "SELECT * FROM user WHERE 1=1 ";
        if(!isEmpty(user.getUserName())){
        	sql += " and userName like '%"+user.getUserName()+"%'";
		}
        if(!isEmpty(user.getPassWord())){
        	sql += " and passWord like '%"+user.getPassWord()+"%'";
		}
        if(!isEmpty(user.getPhone())){
        	sql += " and phone like '%"+user.getPhone()+"%'";
		}
        if(!isEmpty(user.getRealName())){
        	sql += " and realName like '%"+user.getRealName()+"%'";
		}
        if(!isEmpty(user.getSex())){
        	sql += " and sex like '%"+user.getSex()+"%'";
		}
        if(!isEmpty(user.getAddress())){
        	sql += " and address like '%"+user.getAddress()+"%'";
		}
        if(!isEmpty(user.getEmail())){
        	sql += " and email like '%"+user.getEmail()+"%'";
		}
       sql += " ORDER BY ID DESC ";
		Pager<User> pagers = userService.findBySqlRerturnEntity(sql);
		model.addAttribute("pagers", pagers);
		//存储查询条件
		model.addAttribute("obj", user);
		return "user/user";
	}
	
	
	/**
	 * 分页查询 返回list对象(通过Map)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/findByMap")
	public String findByMap(User user, Model model, HttpServletRequest request, HttpServletResponse response) {
		//通过map查询
		Map<String,Object> params = new HashMap<String,Object>();
        if(!isEmpty(user.getUserName())){
        	params.put("userName", user.getUserName());
		}
        if(!isEmpty(user.getPassWord())){
        	params.put("passWord", user.getPassWord());
		}
        if(!isEmpty(user.getPhone())){
        	params.put("phone", user.getPhone());
		}
        if(!isEmpty(user.getRealName())){
        	params.put("realName", user.getRealName());
		}
        if(!isEmpty(user.getSex())){
        	params.put("sex", user.getSex());
		}
        if(!isEmpty(user.getAddress())){
        	params.put("address", user.getAddress());
		}
        if(!isEmpty(user.getEmail())){
        	params.put("email", user.getEmail());
		}
		//分页查询
		Pager<User> pagers = userService.findByMap(params);
		model.addAttribute("pagers", pagers);
		//存储查询条件
		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";
	}
	
	
	/**
	 * 跳至修改页面
	 * @return
	 */
	@RequestMapping(value = "/update")
	public String update(Integer id,Model model) {
		User obj = userService.load(id);
		model.addAttribute("obj",obj);
		return "user/update";
	}
	
	/**
	 * 添加修改
	 * @return
	 */
	@RequestMapping(value = "/exUpdate")
	public String exUpdate(User user, Model model, HttpServletRequest request, HttpServletResponse response) {
		//1.通过实体类修改,可以多传修改条件
		Object attribute = request.getSession().getAttribute("userId");
		if (attribute == null){
			return "redirect:/login/uLogin";
		}
		JSONObject js = new JSONObject();
		user.setId(Integer.valueOf(attribute.toString()));
		userService.updateById(user);
		//2.通过主键id修改
		//userService.updateById(user);
		return "redirect:/user/view.action";
	}
	
	/**
	 * 删除通过主键
	 * @return
	 */
	@RequestMapping(value = "/delete")
	public String delete(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
		///1.通过主键删除
		userService.deleteById(id);
		/*以下是多种删除方式*/
//		//2.通过实体条件删除
//		userService.deleteByEntity(user);
//		//3.通过参数删除
//     //通过map查询
//		Map<String,Object> params = new HashMap<String,Object>();
//		
//        if(!isEmpty(user.getUserName())){
//        	params.put("userName", user.getUserName());
//		}
//       
//        if(!isEmpty(user.getPassWord())){
//        	params.put("passWord", user.getPassWord());
//		}
//       
//        if(!isEmpty(user.getPhone())){
//        	params.put("phone", user.getPhone());
//		}
//       
//        if(!isEmpty(user.getRealName())){
//        	params.put("realName", user.getRealName());
//		}
//       
//        if(!isEmpty(user.getSex())){
//        	params.put("sex", user.getSex());
//		}
//       
//        if(!isEmpty(user.getAddress())){
//        	params.put("address", user.getAddress());
//		}
//       
//        if(!isEmpty(user.getEmail())){
//        	params.put("email", user.getEmail());
//		}
//       
//		userService.deleteByMap(params);
//		//4.状态删除
//		User load = userService.getById(user.getId())
//		load.setIsDelete(1);
//		userService.update(load);
		//5.状态删除
		//User load = userService.load(id);
		//load.setIsDelete(1);
		//userService.update(load);
		return "redirect:/user/findBySql.action";
	}
	
	// --------------------------------------- 华丽分割线 ------------------------------
	// --------------------------------------- 【下面是ajax操作的方法。】 ------------------------------

	/*********************************查询列表【不分页】***********************************************/
	
	/**
	 * 【不分页 => 查询列表 => 无条件】
	* @Title: listAll 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @author
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listAllJson", method = RequestMethod.POST)
	@ResponseBody
	public String listAllJson(User user, HttpServletRequest request, HttpServletResponse response){
		List<User> listAll = userService.listAll();
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("list", listAll);
		jsonObject.put("obj", user);
		return jsonObject.toString();
	}
	
	/**
	 *  【不分页=》查询列表=>有条件】
	* @Title: listByEntity 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @author
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listByEntityJson", method = RequestMethod.POST)
	@ResponseBody
	public String listByEntityJson(User user,  HttpServletRequest request, HttpServletResponse response){
		List<User> listAll = userService.listAllByEntity(user);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("list", listAll);
		jsonObject.put("obj", user);
		return jsonObject.toString();
	}
	
	/**
	 *  【不分页=》查询列表=>有条件】
	* @Title: listByMap 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @author 
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listByMapJson", method = RequestMethod.POST)
	@ResponseBody
	public String listByMapJson(User user,HttpServletRequest request, HttpServletResponse response){
		//通过map查询
		Map<String,Object> params = new HashMap<String,Object>();
	        if(!isEmpty(user.getUserName())){
	        	params.put("userName", user.getUserName());
			}
	        if(!isEmpty(user.getPassWord())){
	        	params.put("passWord", user.getPassWord());
			}
	        if(!isEmpty(user.getPhone())){
	        	params.put("phone", user.getPhone());
			}
	        if(!isEmpty(user.getRealName())){
	        	params.put("realName", user.getRealName());
			}
	        if(!isEmpty(user.getSex())){
	        	params.put("sex", user.getSex());
			}
	        if(!isEmpty(user.getAddress())){
	        	params.put("address", user.getAddress());
			}
	        if(!isEmpty(user.getEmail())){
	        	params.put("email", user.getEmail());
			}
	    List<User> listAll = userService.listByMap(params);
	    JSONObject jsonObject = new JSONObject();
		jsonObject.put("list", listAll);
		jsonObject.put("obj", user);
		return jsonObject.toString();
	}
	
	
	/**
	 * 分页查询 返回list json(通过对象)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/findByObjJson", method = RequestMethod.POST)
	@ResponseBody
	public String findByObjByEntityJson(User user, HttpServletRequest request, HttpServletResponse response) {
		//分页查询
		Pager<User> pagers = userService.findByEntity(user);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("pagers", pagers);
		jsonObject.put("obj", user);
		return jsonObject.toString();
	}
	
	  
	/**
	 * 分页查询 返回list json(通过Map)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/findByMapJson",  method = RequestMethod.POST)
	@ResponseBody
	public String findByMapJson(User user,HttpServletRequest request, HttpServletResponse response) {
		//通过map查询
		Map<String,Object> params = new HashMap<String,Object>();
        if(!isEmpty(user.getUserName())){
        	params.put("userName", user.getUserName());
		}
        if(!isEmpty(user.getPassWord())){
        	params.put("passWord", user.getPassWord());
		}
        if(!isEmpty(user.getPhone())){
        	params.put("phone", user.getPhone());
		}
        if(!isEmpty(user.getRealName())){
        	params.put("realName", user.getRealName());
		}
        if(!isEmpty(user.getSex())){
        	params.put("sex", user.getSex());
		}
        if(!isEmpty(user.getAddress())){
        	params.put("address", user.getAddress());
		}
        if(!isEmpty(user.getEmail())){
        	params.put("email", user.getEmail());
		}
		//分页查询
		Pager<User> pagers = userService.findByMap(params);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("pagers", pagers);
		jsonObject.put("obj", user);
		return jsonObject.toString();
	}
	
	
	/**
	 * ajax 添加
	 * @param 
	 * @return
	 */
	@RequestMapping(value = "/exAddJson", method = RequestMethod.POST)
	@ResponseBody
	public String exAddJson(User user, Model model, HttpServletRequest request, HttpServletResponse response) {
		userService.insert(user);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("message", "添加成功");
		return jsonObject.toString();
	}
	

	/**
	 * ajax 修改
	 * @param 
	 * @return
	 */
	@RequestMapping(value = "/exUpdate.json", method = RequestMethod.POST)
	@ResponseBody
	public String exUpdateJson(User user, Model model, HttpServletRequest request, HttpServletResponse response) {
		//1.通过实体类修改,可以多传修改条件
		userService.updateById(user);
		//2.通过主键id修改
		//userService.updateById(user);
		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.通过主键删除
		userService.deleteById(id);
		/*以下是多种删除方式*/
//		//2.通过实体条件删除
//		userService.deleteByEntity(user);
//		//3.通过参数删除
//        //通过map查询
//		Map<String,Object> params = new HashMap<String,Object>();
//		
//        if(!isEmpty(user.getUserName())){
//        	params.put("userName", user.getUserName());
//		}
//       
//        if(!isEmpty(user.getPassWord())){
//        	params.put("passWord", user.getPassWord());
//		}
//       
//        if(!isEmpty(user.getPhone())){
//        	params.put("phone", user.getPhone());
//		}
//       
//        if(!isEmpty(user.getRealName())){
//        	params.put("realName", user.getRealName());
//		}
//       
//        if(!isEmpty(user.getSex())){
//        	params.put("sex", user.getSex());
//		}
//       
//        if(!isEmpty(user.getAddress())){
//        	params.put("address", user.getAddress());
//		}
//       
//        if(!isEmpty(user.getEmail())){
//        	params.put("email", user.getEmail());
//		}
//       
//		userService.deleteByMap(params);
//		//4.状态删除
//		User load = userService.getById(user.getId())
//		load.setIsDelete(1);
//		userService.updateById(load);
		//5.状态删除
		//User load = userService.load(id);
		//load.setIsDelete(1);
		//userService.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 "";  
    }  
	
	
	/**
	 * springMvc多文件上传
	 * @param files
	 * @param id
	 * @return
	 */
    @RequestMapping(value = "/saveFiles")
    public String saveFiles(@RequestParam("file") CommonsMultipartFile[] files,Integer id,HttpServletRequest request){
		for(int i = 0;i<files.length;i++){
	      	System.out.println("fileName---------->" + files[i].getOriginalFilename());
		  if(!files[i].isEmpty()){
            int pre = (int) System.currentTimeMillis();
	     	try {
			//拿到输出流,同时重命名上传的文件
			 String filePath = request.getRealPath("/upload");
			 File f=new File(filePath);
			 if(!f.exists()){
				f.mkdirs();
			 }
		     String fileNmae=new Date().getTime() + files[i].getOriginalFilename();
		     File file=new File(filePath+"/"+pre + files[i].getOriginalFilename());
			  if(!file.exists()){
				  file.createNewFile();
			 }
			  files[i].transferTo(file);
		     } catch (Exception e) {
				e.printStackTrace();
				System.out.println("上传出错");
			 }
		  }
		}
	  return "";
	}
 // --------------------------------------- 华丽分割线 ------------------------------
	
	
}

订单管理控制层:

@Controller
@RequestMapping("/orderDetail")
public class OrderDetailController extends BaseController {
	
	
	/**
	 * 依赖注入 start dao/service/===
	 */
	@Autowired
	private OrderDetailService orderDetailService;
	
	// --------------------------------------- 华丽分割线 ------------------------------
	
	/*********************************查询列表【不分页】***********************************************/
	
	/**
	 * 【不分页 => 查询列表 => 无条件】
	* @Title: listAll 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @author
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listAll")
	public String listAll(OrderDetail orderDetail, Model model, HttpServletRequest request, HttpServletResponse response){
		List<OrderDetail> listAll = orderDetailService.listAll();
		model.addAttribute("list", listAll);
		return "orderDetail/orderDetail";
	}
	
	/**
	 *  【不分页=》查询列表=>有条件】
	* @Title: listByEntity 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @author
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listByEntity")
	public String listByEntity(OrderDetail orderDetail, Model model, HttpServletRequest request, HttpServletResponse response){
		List<OrderDetail> listAll = orderDetailService.listAllByEntity(orderDetail);
		model.addAttribute("list", listAll);
		return "orderDetail/orderDetail";
	}
	
	/**
	 *  【不分页=》查询列表=>有条件】
	* @Title: listByMap 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @author 
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listByMap")
	public String listByMap(OrderDetail orderDetail, Model model, 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);
		model.addAttribute("list", listAll);
		return "orderDetail/orderDetail";
	}
	
	
	/*********************************查询列表【分页】***********************************************/
	
	
	
	/**
	 * 分页查询 返回list对象(通过对象)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/findByObj")
	public String findByObj(OrderDetail orderDetail, Model model, HttpServletRequest request, HttpServletResponse response) {
		//分页查询
		Pager<OrderDetail> pagers = orderDetailService.findByEntity(orderDetail);
		model.addAttribute("pagers", pagers);
		//存储查询条件
		model.addAttribute("obj", orderDetail);
		return "orderDetail/orderDetail";
	}
	
	/**
	 * 分页查询 返回list对象(通过对By Sql)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/findBySql")
	public String findBySql(OrderDetail orderDetail, Model model, HttpServletRequest request, HttpServletResponse response) {
		//分页查询
		String sql = "SELECT * FROM orderDetail WHERE 1=1 ";
        if(!isEmpty(orderDetail.getItemId())){
        	sql += " and itemId like '%"+orderDetail.getItemId()+"%'";
		}
        if(!isEmpty(orderDetail.getOrderId())){
        	sql += " and orderId like '%"+orderDetail.getOrderId()+"%'";
		}
        if(!isEmpty(orderDetail.getStatus())){
        	sql += " and status like '%"+orderDetail.getStatus()+"%'";
		}
       sql += " ORDER BY ID DESC ";
		Pager<OrderDetail> pagers = orderDetailService.findBySqlRerturnEntity(sql);
		model.addAttribute("pagers", pagers);
		//存储查询条件
		model.addAttribute("obj", orderDetail);
		return "orderDetail/orderDetail";
	}
	
	
	@RequestMapping(value = "/ulist")
	public String ulist(OrderDetail orderDetail, Model model, HttpServletRequest request, HttpServletResponse response) {
		//分页查询
		String sql = "SELECT * FROM order_detail WHERE 1=1 and order_id="+orderDetail.getOrderId();
        if(!isEmpty(orderDetail.getItemId())){
        	sql += " and itemId like '%"+orderDetail.getItemId()+"%'";
		}
       /* if(!isEmpty(orderDetail.getOrderId())){
        	sql += " and orderId like '%"+orderDetail.getOrderId()+"%'";
		}*/
        if(!isEmpty(orderDetail.getStatus())){
        	sql += " and status like '%"+orderDetail.getStatus()+"%'";
		}
       sql += " ORDER BY ID DESC ";
		Pager<OrderDetail> pagers = orderDetailService.findBySqlRerturnEntity(sql);
		model.addAttribute("pagers", pagers);
		//存储查询条件
		model.addAttribute("obj", orderDetail);
		return "orderDetail/ulist";
	}
	/**
	 * 分页查询 返回list对象(通过Map)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/findByMap")
	public String findByMap(OrderDetail orderDetail, Model model, 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());
		}
		//分页查询
		Pager<OrderDetail> pagers = orderDetailService.findByMap(params);
		model.addAttribute("pagers", pagers);
		//存储查询条件
		model.addAttribute("obj", orderDetail);
		return "orderDetail/orderDetail";
	}
	
	/**********************************【增删改】******************************************************/
	
	/**
	 * 跳至添加页面
	 * @return
	 */
	@RequestMapping(value = "/add")
	public String add() {
		return "orderDetail/add";
	}
	
	
	@RequestMapping(value = "/th")
	public String th(Integer id,Model model) {
		OrderDetail obj = orderDetailService.load(id);
		obj.setStatus(1);
		orderDetailService.updateById(obj);
		model.addAttribute("obj",obj);
		return "redirect:/itemOrder/my";
	}

	/**
	 * 跳至详情页面
	 * @return
	 */
	@RequestMapping(value = "/view")
	public String view(Integer id,Model model) {
		OrderDetail obj = orderDetailService.load(id);
		model.addAttribute("obj",obj);
		return "orderDetail/view";
	}
	
	/**
	 * 添加执行
	 * @return
	 */
	@RequestMapping(value = "/exAdd")
	public String exAdd(OrderDetail orderDetail, Model model, HttpServletRequest request, HttpServletResponse response) {
		orderDetailService.insert(orderDetail);
		return "redirect:/orderDetail/findBySql.action";
	}
	
	
	/**
	 * 跳至修改页面
	 * @return
	 */
	@RequestMapping(value = "/update")
	public String update(Integer id,Model model) {
		OrderDetail obj = orderDetailService.load(id);
		model.addAttribute("obj",obj);
		return "orderDetail/update";
	}
	
	/**
	 * 添加修改
	 * @return
	 */
	@RequestMapping(value = "/exUpdate")
	public String exUpdate(OrderDetail orderDetail, Model model, HttpServletRequest request, HttpServletResponse response) {
		//1.通过实体类修改,可以多传修改条件
		orderDetailService.updateById(orderDetail);
		//2.通过主键id修改
		//orderDetailService.updateById(orderDetail);
		return "redirect:/orderDetail/findBySql.action";
	}
	
	/**
	 * 删除通过主键
	 * @return
	 */
	@RequestMapping(value = "/delete")
	public String delete(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
		///1.通过主键删除
		orderDetailService.deleteById(id);
		/*以下是多种删除方式*/
//		//2.通过实体条件删除
//		orderDetailService.deleteByEntity(orderDetail);
//		//3.通过参数删除
//     //通过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());
//		}
//       
//		orderDetailService.deleteByMap(params);
//		//4.状态删除
//		OrderDetail load = orderDetailService.getById(orderDetail.getId())
//		load.setIsDelete(1);
//		orderDetailService.update(load);
		//5.状态删除
		//OrderDetail load = orderDetailService.load(id);
		//load.setIsDelete(1);
		//orderDetailService.update(load);
		return "redirect:/orderDetail/findBySql.action";
	}
	
	// --------------------------------------- 华丽分割线 ------------------------------
	// --------------------------------------- 【下面是ajax操作的方法。】 ------------------------------

	/*********************************查询列表【不分页】***********************************************/
	
	/**
	 * 【不分页 => 查询列表 => 无条件】
	* @Title: listAll 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @author
	* @return String 返回类型 
	* @throws
	 */
	@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 设定文件 
	* @author
	* @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 设定文件 
	* @author 
	* @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);
	    JSONObject jsonObject = new JSONObject();
		jsonObject.put("list", listAll);
		jsonObject.put("obj", orderDetail);
		return jsonObject.toString();
	}
	
	
	/**
	 * 分页查询 返回list json(通过对象)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/findByObjJson", method = RequestMethod.POST)
	@ResponseBody
	public String findByObjByEntityJson(OrderDetail orderDetail, HttpServletRequest request, HttpServletResponse response) {
		//分页查询
		Pager<OrderDetail> pagers = orderDetailService.findByEntity(orderDetail);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("pagers", pagers);
		jsonObject.put("obj", orderDetail);
		return jsonObject.toString();
	}
	
	  
	/**
	 * 分页查询 返回list json(通过Map)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/findByMapJson",  method = RequestMethod.POST)
	@ResponseBody
	public String findByMapJson(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());
		}
		//分页查询
		Pager<OrderDetail> pagers = orderDetailService.findByMap(params);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("pagers", pagers);
		jsonObject.put("obj", orderDetail);
		return jsonObject.toString();
	}
	
	
	/**
	 * ajax 添加
	 * @param 
	 * @return
	 */
	@RequestMapping(value = "/exAddJson", method = RequestMethod.POST)
	@ResponseBody
	public String exAddJson(OrderDetail orderDetail, Model model, HttpServletRequest request, HttpServletResponse response) {
		orderDetailService.insert(orderDetail);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("message", "添加成功");
		return jsonObject.toString();
	}
	

	/**
	 * ajax 修改
	 * @param 
	 * @return
	 */
	@RequestMapping(value = "/exUpdate.json", method = RequestMethod.POST)
	@ResponseBody
	public String exUpdateJson(OrderDetail orderDetail, Model model, HttpServletRequest request, HttpServletResponse response) {
		//1.通过实体类修改,可以多传修改条件
		orderDetailService.updateById(orderDetail);
		//2.通过主键id修改
		//orderDetailService.updateById(orderDetail);
		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.通过主键删除
		orderDetailService.deleteById(id);
		/*以下是多种删除方式*/
//		//2.通过实体条件删除
//		orderDetailService.deleteByEntity(orderDetail);
//		//3.通过参数删除
//        //通过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());
//		}
//       
//		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 "";  
    }  
	
	
	/**
	 * springMvc多文件上传
	 * @param files
	 * @param id
	 * @return
	 */
    @RequestMapping(value = "/saveFiles")
    public String saveFiles(@RequestParam("file") CommonsMultipartFile[] files,Integer id,HttpServletRequest request){
		for(int i = 0;i<files.length;i++){
	      	System.out.println("fileName---------->" + files[i].getOriginalFilename());
		  if(!files[i].isEmpty()){
            int pre = (int) System.currentTimeMillis();
	     	try {
			//拿到输出流,同时重命名上传的文件
			 String filePath = request.getRealPath("/upload");
			 File f=new File(filePath);
			 if(!f.exists()){
				f.mkdirs();
			 }
		     String fileNmae=new Date().getTime() + files[i].getOriginalFilename();
		     File file=new File(filePath+"/"+pre + files[i].getOriginalFilename());
			  if(!file.exists()){
				  file.createNewFile();
			 }
			  files[i].transferTo(file);
		     } catch (Exception e) {
				e.printStackTrace();
				System.out.println("上传出错");
			 }
		  }
		}
	  return "";
	}
 // --------------------------------------- 华丽分割线 ------------------------------
	
	
}

购物车管理控制层:

@Controller
@RequestMapping("/car")
public class CarController extends BaseController {
	@Autowired
	private ItemService itemService;
	@Autowired
	private AddressService addressService;
	/**
	 * 依赖注入 start dao/service/===
	 */
	@Autowired
	private CarService carService;
	
	// --------------------------------------- 华丽分割线 ------------------------------
	
	/*********************************查询列表【不分页】***********************************************/
	
	/**
	 * 【不分页 => 查询列表 => 无条件】
	* @Title: listAll 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @author
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listAll")
	public String listAll(Car car, Model model, HttpServletRequest request, HttpServletResponse response){
		List<Car> listAll = carService.listAll();
		model.addAttribute("list", listAll);
		return "car/car";
	}
	
	/**
	 *  【不分页=》查询列表=>有条件】
	* @Title: listByEntity 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @author
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listByEntity")
	public String listByEntity(Car car, Model model, HttpServletRequest request, HttpServletResponse response){
		List<Car> listAll = carService.listAllByEntity(car);
		model.addAttribute("list", listAll);
		return "car/car";
	}
	
	/**
	 *  【不分页=》查询列表=>有条件】
	* @Title: listByMap 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @author 
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listByMap")
	public String listByMap(Car car, Model model, HttpServletRequest request, HttpServletResponse response){
		//通过map查询
		Map<String,Object> params = new HashMap<String,Object>();
	        if(!isEmpty(car.getItemId())){
	        	params.put("itemId", car.getItemId());
			}
	        if(!isEmpty(car.getUserId())){
	        	params.put("userId", car.getUserId());
			}
	        if(!isEmpty(car.getNum())){
	        	params.put("num", car.getNum());
			}
	        if(!isEmpty(car.getTotal())){
	        	params.put("total", car.getTotal());
			}
	    List<Car> listAll = carService.listByMap(params);
		model.addAttribute("list", listAll);
		return "car/car";
	}
	
	
	/*********************************查询列表【分页】***********************************************/
	
	
	
	/**
	 * 分页查询 返回list对象(通过对象)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/findByObj")
	public String findByObj(Car car, Model model, HttpServletRequest request, HttpServletResponse response) {
		//分页查询
		Pager<Car> pagers = carService.findByEntity(car);
		model.addAttribute("pagers", pagers);
		//存储查询条件
		model.addAttribute("obj", car);
		return "car/car";
	}
	
	/**
	 * 分页查询 返回list对象(通过对By Sql)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/findBySql")
	public String findBySql(Car car, 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 car WHERE 1=1 and user_id = "+userId;
        if(!isEmpty(car.getItemId())){
        	sql += " and itemId like '%"+car.getItemId()+"%'";
		}
        if(!isEmpty(car.getUserId())){
        	sql += " and userId like '%"+car.getUserId()+"%'";
		}
        if(!isEmpty(car.getNum())){
        	sql += " and num like '%"+car.getNum()+"%'";
		}
        if(!isEmpty(car.getTotal())){
        	sql += " and total like '%"+car.getTotal()+"%'";
		}
       sql += " ORDER BY ID DESC ";
		List<Car> listBySqlReturnEntity = carService.listBySqlReturnEntity(sql);
		model.addAttribute("list", listBySqlReturnEntity);
		//存储查询条件
		model.addAttribute("obj", car);
		return "car/car";
	}
	
	
	/**
	 * 分页查询 返回list对象(通过Map)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/findByMap")
	public String findByMap(Car car, Model model, HttpServletRequest request, HttpServletResponse response) {
		//通过map查询
		Map<String,Object> params = new HashMap<String,Object>();
        if(!isEmpty(car.getItemId())){
        	params.put("itemId", car.getItemId());
		}
        if(!isEmpty(car.getUserId())){
        	params.put("userId", car.getUserId());
		}
        if(!isEmpty(car.getNum())){
        	params.put("num", car.getNum());
		}
        if(!isEmpty(car.getTotal())){
        	params.put("total", car.getTotal());
		}
		//分页查询
		Pager<Car> pagers = carService.findByMap(params);
		model.addAttribute("pagers", pagers);
		//存储查询条件
		model.addAttribute("obj", car);
		return "car/car";
	}
	
	/**********************************【增删改】******************************************************/
	
	/**
	 * 跳至添加页面
	 * @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());
			valueOf= bg.doubleValue();
		}
		Integer num = car.getNum();
		Double t = valueOf*num;
		
		 BigDecimal bg = new BigDecimal(t).setScale(2, RoundingMode.UP);
		 double doubleValue = bg.doubleValue();
		car.setTotal(doubleValue+"");
		carService.insert(car);
		js.put("res", 1);
		return js.toJSONString();
	}
	
	
	/**
	 * 跳至修改页面
	 * @return
	 */
	@RequestMapping(value = "/update")
	public String update(Integer id,Model model) {
		Car obj = carService.load(id);
		model.addAttribute("obj",obj);
		return "car/update";
	}
	
	
	@RequestMapping(value = "/js")
	@ResponseBody
	public String js(@RequestBody List<CarDto> list,Model model,HttpServletRequest request) {
		
		
		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());
		String key = "car_"+userId;
		request.getSession().setAttribute(key, list);
		js.put("res", 1);
		return js.toJSONString();
	}
	
	
	
	@RequestMapping(value = "/js2")
	@ResponseBody
	public String js2(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();
		Long valueOf = Long.valueOf(price);
		Integer num = car.getNum();
		Long t = valueOf*num;
		car.setTotal(t.toString());
		carService.insert(car);
		String key = "car_"+userId;
		List<CarDto> list = new ArrayList<CarDto>();
		CarDto d = new CarDto();
		d.setId(car.getId());
		d.setNum(car.getNum());
		list.add(d);
		request.getSession().setAttribute(key, list);
		js.put("res", 1);
		return js.toJSONString();
	}
	
	/**
	 * 添加修改
	 * @return
	 */
	@RequestMapping(value = "/exUpdate")
	public String exUpdate(Car car, Model model, HttpServletRequest request, HttpServletResponse response) {
		//1.通过实体类修改,可以多传修改条件
		carService.updateById(car);
		//2.通过主键id修改
		//carService.updateById(car);
		return "redirect:/car/findBySql.action";
	}
	
	/**
	 * 删除通过主键
	 * @return
	 */
	@RequestMapping(value = "/delete")
	@ResponseBody
	public String delete(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
		///1.通过主键删除
		carService.deleteById(id);
		/*以下是多种删除方式*/
//		//2.通过实体条件删除
//		carService.deleteByEntity(car);
//		//3.通过参数删除
//     //通过map查询
//		Map<String,Object> params = new HashMap<String,Object>();
//		
//        if(!isEmpty(car.getItemId())){
//        	params.put("itemId", car.getItemId());
//		}
//       
//        if(!isEmpty(car.getUserId())){
//        	params.put("userId", car.getUserId());
//		}
//       
//        if(!isEmpty(car.getNum())){
//        	params.put("num", car.getNum());
//		}
//       
//        if(!isEmpty(car.getTotal())){
//        	params.put("total", car.getTotal());
//		}
//       
//		carService.deleteByMap(params);
//		//4.状态删除
//		Car load = carService.getById(car.getId())
//		load.setIsDelete(1);
//		carService.update(load);
		//5.状态删除
		//Car load = carService.load(id);
		//load.setIsDelete(1);
		//carService.update(load);
		return "redirect:/car/findBySql.action";
	}
	
	// --------------------------------------- 华丽分割线 ------------------------------
	// --------------------------------------- 【下面是ajax操作的方法。】 ------------------------------

	/*********************************查询列表【不分页】***********************************************/
	
	/**
	 * 【不分页 => 查询列表 => 无条件】
	* @Title: listAll 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @author
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listAllJson", method = RequestMethod.POST)
	@ResponseBody
	public String listAllJson(Car car, HttpServletRequest request, HttpServletResponse response){
		List<Car> listAll = carService.listAll();
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("list", listAll);
		jsonObject.put("obj", car);
		return jsonObject.toString();
	}
	
	/**
	 *  【不分页=》查询列表=>有条件】
	* @Title: listByEntity 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @author
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listByEntityJson", method = RequestMethod.POST)
	@ResponseBody
	public String listByEntityJson(Car car,  HttpServletRequest request, HttpServletResponse response){
		List<Car> listAll = carService.listAllByEntity(car);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("list", listAll);
		jsonObject.put("obj", car);
		return jsonObject.toString();
	}
	
	/**
	 *  【不分页=》查询列表=>有条件】
	* @Title: listByMap 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param @return 设定文件 
	* @author 
	* @return String 返回类型 
	* @throws
	 */
	@RequestMapping(value = "/listByMapJson", method = RequestMethod.POST)
	@ResponseBody
	public String listByMapJson(Car car,HttpServletRequest request, HttpServletResponse response){
		//通过map查询
		Map<String,Object> params = new HashMap<String,Object>();
	        if(!isEmpty(car.getItemId())){
	        	params.put("itemId", car.getItemId());
			}
	        if(!isEmpty(car.getUserId())){
	        	params.put("userId", car.getUserId());
			}
	        if(!isEmpty(car.getNum())){
	        	params.put("num", car.getNum());
			}
	        if(!isEmpty(car.getTotal())){
	        	params.put("total", car.getTotal());
			}
	    List<Car> listAll = carService.listByMap(params);
	    JSONObject jsonObject = new JSONObject();
		jsonObject.put("list", listAll);
		jsonObject.put("obj", car);
		return jsonObject.toString();
	}
	
	
	/**
	 * 分页查询 返回list json(通过对象)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/findByObjJson", method = RequestMethod.POST)
	@ResponseBody
	public String findByObjByEntityJson(Car car, HttpServletRequest request, HttpServletResponse response) {
		//分页查询
		Pager<Car> pagers = carService.findByEntity(car);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("pagers", pagers);
		jsonObject.put("obj", car);
		return jsonObject.toString();
	}
	
	  
	/**
	 * 分页查询 返回list json(通过Map)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/findByMapJson",  method = RequestMethod.POST)
	@ResponseBody
	public String findByMapJson(Car car,HttpServletRequest request, HttpServletResponse response) {
		//通过map查询
		Map<String,Object> params = new HashMap<String,Object>();
        if(!isEmpty(car.getItemId())){
        	params.put("itemId", car.getItemId());
		}
        if(!isEmpty(car.getUserId())){
        	params.put("userId", car.getUserId());
		}
        if(!isEmpty(car.getNum())){
        	params.put("num", car.getNum());
		}
        if(!isEmpty(car.getTotal())){
        	params.put("total", car.getTotal());
		}
		//分页查询
		Pager<Car> pagers = carService.findByMap(params);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("pagers", pagers);
		jsonObject.put("obj", car);
		return jsonObject.toString();
	}
	
	
	/**
	 * ajax 添加
	 * @param 
	 * @return
	 */
	@RequestMapping(value = "/exAddJson", method = RequestMethod.POST)
	@ResponseBody
	public String exAddJson(Car car, Model model, HttpServletRequest request, HttpServletResponse response) {
		carService.insert(car);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("message", "添加成功");
		return jsonObject.toString();
	}
	

	/**
	 * ajax 修改
	 * @param 
	 * @return
	 */
	@RequestMapping(value = "/exUpdate.json", method = RequestMethod.POST)
	@ResponseBody
	public String exUpdateJson(Car car, Model model, HttpServletRequest request, HttpServletResponse response) {
		//1.通过实体类修改,可以多传修改条件
		carService.updateById(car);
		//2.通过主键id修改
		//carService.updateById(car);
		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.通过主键删除
		carService.deleteById(id);
		/*以下是多种删除方式*/
//		//2.通过实体条件删除
//		carService.deleteByEntity(car);
//		//3.通过参数删除
//        //通过map查询
//		Map<String,Object> params = new HashMap<String,Object>();
//		
//        if(!isEmpty(car.getItemId())){
//        	params.put("itemId", car.getItemId());
//		}
//       
//        if(!isEmpty(car.getUserId())){
//        	params.put("userId", car.getUserId());
//		}
//       
//        if(!isEmpty(car.getNum())){
//        	params.put("num", car.getNum());
//		}
//       
//        if(!isEmpty(car.getTotal())){
//        	params.put("total", car.getTotal());
//		}
//       
//		carService.deleteByMap(params);
//		//4.状态删除
//		Car load = carService.getById(car.getId())
//		load.setIsDelete(1);
//		carService.updateById(load);
		//5.状态删除
		//Car load = carService.load(id);
		//load.setIsDelete(1);
		//carService.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 "";  
    }  
	
	
	/**
	 * springMvc多文件上传
	 * @param files
	 * @param id
	 * @return
	 */
    @RequestMapping(value = "/saveFiles")
    public String saveFiles(@RequestParam("file") CommonsMultipartFile[] files,Integer id,HttpServletRequest request){
		for(int i = 0;i<files.length;i++){
	      	System.out.println("fileName---------->" + files[i].getOriginalFilename());
		  if(!files[i].isEmpty()){
            int pre = (int) System.currentTimeMillis();
	     	try {
			//拿到输出流,同时重命名上传的文件
			 String filePath = request.getRealPath("/upload");
			 File f=new File(filePath);
			 if(!f.exists()){
				f.mkdirs();
			 }
		     String fileNmae=new Date().getTime() + files[i].getOriginalFilename();
		     File file=new File(filePath+"/"+pre + files[i].getOriginalFilename());
			  if(!file.exists()){
				  file.createNewFile();
			 }
			  files[i].transferTo(file);
		     } catch (Exception e) {
				e.printStackTrace();
				System.out.println("上传出错");
			 }
		  }
		}
	  return "";
	}
 // --------------------------------------- 华丽分割线 ------------------------------
	
	
}

源码获取:俺的博客首页 "资源" 里下载!

Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐