基于javaweb和mysql的ssm茶叶售卖商城系统(java+ssm+jsp+easyui+mysql)

私信源码获取及调试交流

私信源码获取及调试交流

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

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

适用

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

功能说明

基于javaweb的SSM茶叶售卖商城系统(java+ssm+jsp+easyui+mysql)

这是一个应用SSM框架的项目,前端页面整洁清晰。该系统有两个角色,一个是普通用户,另一个是管理员。

普通用户具有注册、登录、查看商品、添加购物车、添加商品收藏、下订单、商品评价、用户地址管理等等功能。

管理员具有登录、管理用户信息、管理商品信息、管理商品活动信息、管理订单信息、管理用户评论信息的等等功能。

应用技术:Jsp + SSM + EasyUi

运行环境:eclipse/IDEA + MySQL5.7 + Tomcat8.5 + JDK1.8

	
	@Autowired
	private CommentService commentService;
	
	@Autowired
	private ShoppingService shoppingService;
	
	/**
	 * 商品列表信息页面
	 */
	@RequestMapping(value="/list",method=RequestMethod.GET)
	public ModelAndView index(ModelAndView model,Long categoryId,Page page,
			Long price,Long sale,Long comment,Long flag,Long flag2,String name,
			HttpServletRequest request){
		Map<String, Object> queryMap = new HashMap<String, Object>();
		model.addObject("teaCategoryList", teaCategoryService.findAll());
		
		//如果从其他页面访问,商品种类权限重置下
		if(flag2 != null)
		{
			request.getSession().setAttribute("categoryId", null);
		}
		if(categoryId != null && price == null && comment == null && sale == null && flag==null)
		{
			request.getSession().setAttribute("price", null);
			request.getSession().setAttribute("sale", null);
			request.getSession().setAttribute("comment", null);
		}
		
		if(price == null && sale==null && comment == null && categoryId == null && flag == null)
		{
			request.getSession().setAttribute("price", null);
			request.getSession().setAttribute("sale", null);
			request.getSession().setAttribute("comment", null);
			request.getSession().setAttribute("categoryId", null);
		}
		if(categoryId != null)
		{
			request.getSession().setAttribute("categoryId", null); //之前权限取消
			request.getSession().setAttribute("categoryId", categoryId);  //创建爱你新权限
			queryMap.put("categoryId", categoryId);
			
		}else {
			Long pre_categoryId = (Long)request.getSession().getAttribute("categoryId");
			queryMap.put("categoryId", pre_categoryId);
		}
		
		
		if(price == null)
		{
			Long pre_price = (Long)request.getSession().getAttribute("price");
			if(pre_price != null)
			{
		model.setViewName("log/list");
		return model;
	}
	
	/**
	 * 获取日志列表
	 * @param page
	 * @param content
	 * @param roleId
	 * @param sex
	 * @return
	 */
	@RequestMapping(value="/list",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> getList(Page page,
			@RequestParam(name="content",required=false,defaultValue="") String content
			){
		Map<String, Object> ret = new HashMap<String, Object>();
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put("content", content);
		queryMap.put("offset", page.getOffset());
		queryMap.put("pageSize", page.getRows());
		ret.put("rows", logService.findList(queryMap));
		ret.put("total", logService.getTotal(queryMap));
		return ret;
	}
	
	/**
	 * 添加日志
	 * @param user
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, String> add(Log log){
		Map<String, String> ret = new HashMap<String, String>();
		if(log == null){
			ret.put("type", "error");
			ret.put("msg", "请填写正确的日志信息!");
			return ret;
		}
		if(StringUtils.isEmpty(log.getContent())){
			ret.put("type", "error");
			ret.put("msg", "请填写日志内容!");
			return ret;
		}
	@ResponseBody
	public Map<String, String> add(User user){
		Map<String, String> ret = new HashMap<String, String>();
		if(user == null){
			ret.put("type", "error");
			ret.put("msg", "请填写正确的用户信息!");
			return ret;
		}
		if(StringUtils.isEmpty(user.getUsername())){
			ret.put("type", "error");
			ret.put("msg", "请填写用户名!");
			return ret;
		}
		if(StringUtils.isEmpty(user.getPassword())){
			ret.put("type", "error");
			ret.put("msg", "请填写密码!");
			return ret;
		}
		if(user.getRoleId() == null){
			ret.put("type", "error");
			ret.put("msg", "请选择所属角色!");
			return ret;
		}
		if(isExist(user.getUsername(), 0l)){
			ret.put("type", "error");
			ret.put("msg", "该用户名已经存在,请重新输入!");
			return ret;
		}
		if(userService.add(user) <= 0){
			ret.put("type", "error");
			ret.put("msg", "用户添加失败,请联系管理员!");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "用户添加成功!");
		return ret;
	}
	
	/**
	 * 编辑用户
	 * @param user
	 * @return
			ret.put("msg", "订单删除失败,请联系管理员!");
			return ret;
		}else {
			ret.put("type", "success");
			ret.put("msg", "订单删除成功!");
			return ret;
		}
		
	}
	
	
	/**
	 * 用户保存地址
	 * @param user
	 * @return
	 */
	@RequestMapping(value="/add_address",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, String> save_address(Address address,HttpServletRequest request){
		Map<String, String> ret = new HashMap<String, String>();
		
		if(StringUtils.isEmpty(address.getName())){
			ret.put("type", "error");
			ret.put("msg", "收件人姓名不能为空!");
			return ret;
		}
		if(StringUtils.isEmpty(address.getProvince())){
			ret.put("type", "error");
			ret.put("msg", "省份不能为空!");
			return ret;
		}
		if(StringUtils.isEmpty(address.getArea())&&StringUtils.isEmpty(address.getCity())){
			ret.put("type", "error");
			ret.put("msg", "市/县和区/县至少填一个!");
			return ret;
		}
		if(StringUtils.isEmpty(address.getDetail())){
			ret.put("type", "error");
			ret.put("msg", "收货地址不能为空!");
			return ret;
		}
		if(StringUtils.isEmpty(address.getPostcode())){
			ret.put("type", "error");
			ret.put("msg", "邮编不能为空!");
			ret.put("type", "error");
			ret.put("msg", "请填写评论量!");
			return ret;
		}
		if(StringUtils.isEmpty(String.valueOf(tea.getSaleNumber()))){
			ret.put("type", "error");
			ret.put("msg", "请填写销售量!");
			return ret;
		}
		if(isExist(tea.getName(), tea.getId())){
			ret.put("type", "error");
			ret.put("msg", "该商品名已经存在,请重新输入!");
			return ret;
		}
		
		Tea t = teaService.findByTeaId(String.valueOf(tea.getId())); //原先Tea对应的actionId
		//不等就要进行数量更换操作
		if(t.getActionId() != tea.getActionId())
		{
			Action pre_a = actionService.findByActionId(String.valueOf(t.getActionId())); //原先的action
			Action new_a = actionService.findByActionId(String.valueOf(tea.getActionId())); //新的action
			if(new_a.getNow_num() == new_a.getMax_num())
			{
				ret.put("type", "error");
				ret.put("msg", "商品编辑失败,新编辑活动已达最大限制个数!");
				return ret;
			}
			//原先action对应now_num减一
			if(actionService.reduceNowNum(pre_a.getId()) == 0 )
			{
				ret.put("type", "error");
				ret.put("msg", "活动数量编辑失败,请联系管理员!");
				return ret;
			}
			//新action对应now_num加一
			if(actionService.addNowNum(tea)<=0)
			{
				ret.put("type", "error");
				ret.put("msg", "活动数量编辑失败,请联系管理员!");
				return ret;
			}
			ret.put("msg", "请填写用户名!");
			return ret;
		}
		if(StringUtils.isEmpty(account.getPassword())){
			ret.put("type", "error");
			ret.put("msg", "请填写密码!");
			return ret;
		}
		if(StringUtils.isEmpty(account.getRealname())){
			ret.put("type", "error");
			ret.put("msg", "请填写真实姓名!");
			return ret;
		}
		if(account.getPhone() == null){
			ret.put("type", "error");
			ret.put("msg", "请填写电话号码!");
			return ret;
		}
		if(isExist(account.getUsername(), account.getId())){
			ret.put("type", "error");
			ret.put("msg", "该用户名已经存在,请重新输入!");
			return ret;
		}
		if(accountService.edit(account) <= 0){
			ret.put("type", "error");
			ret.put("msg", "用户编辑失败,请联系管理员!");
			return ret;
		}
		if(accountService.editPassword(account) <= 0){
			ret.put("type", "error");
			ret.put("msg", "用户密码编辑失败,请联系管理员!");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "用户编辑成功!");
		return ret;
	}
	
	
	/**
	 * 批量删除评论
	 * @param ids
	 * @return
	 */
	@RequestMapping(value="/delete_comment",method=RequestMethod.POST)

/**
 *前端系统用户登录控制类 
 *
 */
@Controller
@RequestMapping("/home")
public class ShopLoginController {

	@Autowired
	private AccountService accountService;
	
	@Autowired
	private LogService logService;
	
	@Autowired
	private ShoppingService shoppingService;
	
	/**
	 * 前端系统登录页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/login",method=RequestMethod.GET)
			ids = ids.substring(0,ids.length()-1);
		}
		if(userService.delete(ids) <= 0){
			ret.put("type", "error");
			ret.put("msg", "用户删除失败,请联系管理员!");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "用户删除成功!");
		return ret;
	}
	
	/**
	 * 上传图片
	 * @param photo
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/upload_photo",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, String> uploadPhoto(MultipartFile photo,HttpServletRequest request){
		Map<String, String> ret = new HashMap<String, String>();
		if(photo == null){
			ret.put("type", "error");
			ret.put("msg", "选择要上传的文件!");
			return ret;
		}
		if(photo.getSize() > 1024*1024*1024){
			ret.put("type", "error");
			ret.put("msg", "文件大小不能超过10M!");
			return ret;
		}
		//获取文件后缀
		String suffix = photo.getOriginalFilename().substring(photo.getOriginalFilename().lastIndexOf(".")+1,photo.getOriginalFilename().length());
		if(!"jpg,jpeg,gif,png".toUpperCase().contains(suffix.toUpperCase())){
			ret.put("type", "error");
			ret.put("msg", "请选择jpg,jpeg,gif,png格式的图片!");
			return ret;
		}
		String savePath = request.getServletContext().getRealPath("/") + "/resources/upload/";
		File savePathFile = new File(savePath);
		if(!savePathFile.exists()){
			ret.put("msg", "选择要删除的数据!");
			return ret;
		}
		if(ids.contains(",")){
			ids = ids.substring(0,ids.length()-1);
		}
		String[] split = ids.split(",");
		// 减少评论对应商品的评论数
		for(String str : split) {
			Comment comment = commentService.findById(Long.valueOf(str));
			Tea findByTeaId = teaService.findByTeaId(String.valueOf(comment.getProductId()));
			findByTeaId.setCommentNumber(findByTeaId.getCommentNumber()-1);
			teaService.edit(findByTeaId);
		}
		if(commentService.delete(ids) <= 0){
			ret.put("type", "error");
			ret.put("msg", "评论删除失败,请联系管理员!");
			return ret;
		}
	
		ret.put("type", "success");
		ret.put("msg", "评论删除成功!");
		return ret;
	}
	
	/**
	 * 批量删除账户
	 * @param ids
	 * @return
	 */
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, String> delete(String ids){
		Map<String, String> ret = new HashMap<String, String>();
		if(StringUtils.isEmpty(ids)){
			ret.put("type", "error");
			ret.put("msg", "选择要删除的数据!");
			return ret;
		}
		if(ids.contains(",")){
			ids = ids.substring(0,ids.length()-1);
		}
		String[] split = ids.split(",");
		for(String str : split) {
			// 删除与账户有关的评论信息
			commentService.deleteByAccountId(Long.valueOf(str));
			shoppingService.deleteByAccountId(Long.valueOf(str));
			ordersService.deleteByAccountId(Long.valueOf(str));
			view_LogService.deleteByAccountId(Long.valueOf(str));
		model.setViewName("system/index");
		return model;//WEB-INF/views/+system/index+.jsp = WEB-INF/views/system/index.jsp
	}
	
	/**
	 * 系统登录后的欢迎页
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/welcome",method=RequestMethod.GET)
	public ModelAndView welcome(ModelAndView model){
		model.setViewName("system/welcome");
		return model;
	}
	/**
	 * 登陆页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/login",method=RequestMethod.GET)
	public ModelAndView login(ModelAndView model){
		model.setViewName("system/login");
		return model;
	}
	
	/**
	 * 登录表单提交处理控制器
	 * @param user
	 * @param cpacha
	 * @return
	 */
	@RequestMapping(value="/login",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, String> loginAct(User user,String cpacha,HttpServletRequest request){
		Map<String, String> ret = new HashMap<String, String>();
		if(user == null){
			ret.put("type", "error");
			ret.put("msg", "请填写用户信息!");
			return ret;
		}
		if(StringUtils.isEmpty(cpacha)){
			ret.put("type", "error");
			ret.put("msg", "请填写验证码!");
			return ret;
		}
		if(StringUtils.isEmpty(user.getUsername())){
	
	/**
     * 订单统计柱形图表页面
     * @param model
     * @return
     */
    @RequestMapping(value = "/chart_bar", method = RequestMethod.GET)
    public ModelAndView chartBar(ModelAndView model){
        model.setViewName("order/chart_bar");
        return model;
    }
	
	/**
	 * 获取订单列表
	 * @param page
	 * @param name
	 * @return
	 */
	@RequestMapping(value="/list",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> getOrderList(Page page,
			@RequestParam(name="id",required=false,defaultValue="") String id
			){
		Map<String, Object> ret = new HashMap<String, Object>();
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put("offset", page.getOffset());
		queryMap.put("pageSize", page.getRows());
		queryMap.put("id", id);
		List<Orders> findList = ordersService.findAllOrders(queryMap);
		double price = 0; //计算每个订单的总价
		String item = ""; //记录每个订单对应的商品详情
		String address = ""; //送货地址
		for(Orders order : findList) {
			//获取订单所属用户
			Account account = accountService.findById(order.getAccount_Id());
			order.setAccount(account);
			//获取送货地址
			Address findByAccountId = addressService.findByAccountId(account.getId());
			address = address + findByAccountId.getProvince() + findByAccountId.getCity() + findByAccountId.getArea() + findByAccountId.getDetail();
			order.setAddress(address);
			//获取订单详情
			List<Shopping> shoppingList = shoppingService.findByIds(order.getShopping_Id());
			for(Shopping shopping : shoppingList) {
				//取出商品
		if(findChildernList != null && findChildernList.size() > 0){
			//表示该分类下存在子分类,不能删除
			ret.put("type", "error");
			ret.put("msg", "该分类下存在子分类,不能删除!");
			return ret;
		}
		// 删除与此菜单有关的其他信息
		authorityService.deleteByMenuId(id);
		if(menuService.delete(id) == 0){
			ret.put("type", "error");
			ret.put("msg", "删除失败,请联系管理员!");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "删除成功!");
		return ret;
	}
}

/**
 * 前端注册用户控制器
 *
 */
	private TeaService teaService;
	

	@Autowired
	private ShoppingService shoppingService;
	
	@Autowired
	private AddressService addressService;
	
	@Autowired
	private OrdersService ordersService;
	
	/**
	 * 用户个人信息页面
	 */
	@RequestMapping(value="/info",method=RequestMethod.GET)
	public ModelAndView index(ModelAndView model,HttpServletRequest request){
		model.addObject("teaCategoryList", teaCategoryService.findAll());
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put("actionId", 3);
		model.addObject("teaListByActionId", teaService.findList(queryMap));
		
		Account account = (Account) request.getSession().getAttribute("account");
		Map<String, Object> queryMap2 = new HashMap<String, Object>();
		queryMap2.put("accountId",account.getId());
		queryMap2.put("state","未支付");
		model.addObject("cartList",shoppingService.findList(queryMap2));
		model.addObject("cartTotal",shoppingService.getTotal(queryMap2));
		
		
		model.setViewName("home/account/info");
		return model;
	}
	
	/**
	 * 用户评论页面
	 */
	@RequestMapping(value="/comment",method=RequestMethod.GET)
	public ModelAndView comment(ModelAndView model,Page page,HttpServletRequest request){
		model.addObject("teaCategoryList", teaCategoryService.findAll());
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put("actionId", 2);
		model.addObject("teaListByActionId", teaService.findList(queryMap));
	 * 判断该商品名是否存在
	 * @param username
	 * @param id
	 * @return
	 */
	private boolean isExist(String name,Long id){
		Tea tea = teaService.findByTeaname(name);
		if(tea == null)return false;
		if(tea.getId().longValue() == id.longValue())return false;
		return true;
	}
}

/**
* 账户管理控制器
 *
 */
@Controller
@RequestMapping("/home")
public class ShopRegisterController {
	@Autowired
	private AccountService accountService;
	
	@Autowired
	private ShoppingService shoppingService;
	
	/**
	 * 前端注册用户页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/register",method=RequestMethod.GET)
	public ModelAndView index(ModelAndView model,HttpServletRequest request){
		Account account = (Account) request.getSession().getAttribute("account");
		if(account!=null)
		{
			Map<String, Object> queryMap = new HashMap<String, Object>();
			queryMap.put("accountId",account.getId());
			queryMap.put("state","未支付");
			model.addObject("cartTotal",shoppingService.getTotal(queryMap));
		}
		
		
		model.setViewName("home/register/index");
		return model;
	}
	
	/**
	 * 前端用户注册信息接收保存
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, String> addAccount(Account account,String cpacha,String confirm_password,HttpServletRequest request){
		Map<String, String> ret = new HashMap<String, String>();
		if(account == null){
			ret.put("type", "error");
			ret.put("msg", "请填写正确的注册信息!");
			return ret;
		if(registerCpacha == null){
			ret.put("type", "error");
			ret.put("msg", "验证码已失效,请刷新页面!");
			return ret;
		}
		if(!cpacha.toUpperCase().equals(registerCpacha.toString().toUpperCase())){
			ret.put("type", "error");
			ret.put("msg", "验证码错误!");
			return ret;
		}

		if(isExist(account.getUsername(), 0l)){
			ret.put("type", "error");
			ret.put("msg", "该用户名已经存在,请重新输入!");
			return ret;
		}
		
		//默认性别和照片
		account.setSex(0);
		account.setPhoto("../../resources/home/images/people.png");
		if(accountService.add(account) <= 0){
			ret.put("type", "error");
			ret.put("msg", "用户添加失败,请联系管理员!");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "角色添加成功!");
		return ret;
	}
	/**
	 * 判断该用户名是否存在
	 * @param username
	 * @param id
	 * @return
	 */
	private boolean isExist(String username,Long id){
		Account account = accountService.findByUsername(username);
		if(account == null)return false;
		if(account.getId().longValue() == id.longValue())return false;
		return true;
	}
}
	@Autowired
	private AddressService addressService;
	
	@Autowired
	private CollectService collectService;
	
	@Autowired
	private TeaService teaService;
	
	/**
	 * 账户列表页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/list",method=RequestMethod.GET)
	public ModelAndView list(ModelAndView model){
		
		
		model.setViewName("account/list");
		return model;
	}
	/**
	 * 获取账户留言列表
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/comment",method=RequestMethod.GET)
	public ModelAndView comment(ModelAndView model){
		
		model.setViewName("account/comment");
		return model;
	}
	
	/**
	 * 获取评论列表
	 * @param page
	 * @param username
	 * @param roleId
	 * @param sex
	 * @return
	 */
	@RequestMapping(value="/comment",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> getComment(Page page,
			@RequestParam(name="content",required=false,defaultValue="") String content
			){
		Map<String, Object> ret = new HashMap<String, Object>();
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put("content", content);
	
		queryMap.put("offset", page.getOffset());
		queryMap.put("pageSize", page.getRows());
		ret.put("rows", commentService.findList(queryMap));
		}
		if(ids.contains(",")){
			ids = ids.substring(0,ids.length()-1);
		}
		String[] idArr = ids.split(",");
		if(idArr.length > 0){
			authorityService.deleteByRoleId(roleId);
		}
		for(String id:idArr){
			Authority authority = new Authority();
			authority.setMenuId(Long.valueOf(id));
			authority.setRoleId(roleId);
			authorityService.add(authority);
		}
		ret.put("type", "success");
		ret.put("msg", "权限编辑成功!");
		return ret;
	}
	
	/**
	 * 获取某个角色的所有权限
	 * @param roleId
	 * @return
	 */
	@RequestMapping(value="/get_role_authority",method=RequestMethod.POST)
	@ResponseBody
	public List<Authority> getRoleAuthority(
			@RequestParam(name="roleId",required=true) Long roleId
		){
		return authorityService.findListByRoleId(roleId);
	}
}

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

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐