current position:Home>Java project: fruit and vegetable mall system (java + SSM + jsp + MySQL)

Java project: fruit and vegetable mall system (java + SSM + jsp + MySQL)

2022-01-27 05:07:24 qq_ one billion three hundred and thirty-four million six hundr

Project description : This is a base SSM Fruit and vegetable mall system based on Framework Development . First , This project page is concise and refreshing , Easy to understand and learn . secondly , This project is rich in functions , It has all the functions of an online fruit and vegetable mall , And it also involves Sandbox Alipay payment And other technical highlights .

Project functions : This project is divided into three roles : Customer 、 Sellers and administrators . Customer Login registration 、 Browse product information 、 Add cart 、 Payment order 、 Collect goods 、 Comment on products and other functions . The seller Have the ability to manage their own goods 、 Manage your own orders 、 Manage your personal information and so on . Administrators Manage all user information 、 Manage all product information 、 Manage all comments 、 Manage product category information 、 Manage all order information, etc .

applied technology :Jsp + SSM + MySQL + Sandbox Alipay

Running environment :Eclipse/IntelliJ IDEA + MySQL5.7( Built in project package ) + Tomcat7.0( Built in project package ) + JDK1.8

 

 

 

 

 

Order control layer :

/**
 *  Order management controller 
 * @author yy
 *
 */
@RequestMapping("/admin/order")
@Controller
public class OrderController {
	
	
	@Autowired
	private OrderService orderService;
	
	@Autowired
	private AccountService accountService;
	
	@Autowired
	private UserService userService;
	
	
	
	/**
	 *  Order list page 
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/list",method=RequestMethod.GET)
	public ModelAndView list(ModelAndView model){
		model.setViewName("order/list");
		model.addObject("accountList", JSONArray.fromObject(accountService.findList(new HashMap<String, Object>())));
		model.addObject("userList",  JSONArray.fromObject(userService.findList(new HashMap<String, Object>())));
		return model;
	}
	
	
	/**
	 *  Check the order list 
	 * @param sn
	 * @param page
	 * @return
	 */
	@RequestMapping(value="/list",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> list(@RequestParam(name="sn",defaultValue="")String sn,
			@RequestParam(name="username",required=false)String username,
			@RequestParam(name="moneyMin",required=false)Double moneyMin,
			@RequestParam(name="moneyMax",required=false)Double moneyMax,
			@RequestParam(name="status",required=false)Integer status,
				Page page, HttpServletRequest request
			){
		Map<String, Object> ret = new HashMap<String, Object>();
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put("sn", sn);
		if(!StringUtils.isEmpty(username)){
			Account account = accountService.findByName(username);
			if(account != null){
				queryMap.put("userId", account.getId());
			}
		}
		if(moneyMin != null){
			queryMap.put("moneyMin", moneyMin);
		}
		if(moneyMax != null){
			queryMap.put("moneyMax", moneyMax);
		}
		if(status != null){
			queryMap.put("status", status);
		}
		Role role = (Role) request.getSession().getAttribute("role");
		User user = (User) request.getSession().getAttribute("admin");
		if(role.getId().equals(Long.valueOf("2"))) {
			// If it's a seller role ,  You can only see your own orders 
			queryMap.put("sellerId", user.getId());
		}
		queryMap.put("offset", page.getOffset());
		queryMap.put("pageSize", page.getRows());
		ret.put("rows", orderService.findList(queryMap));
		ret.put("total", orderService.getTotal(queryMap));
		return ret;
	}
	
	/**
	 *  According to the order id Query order sub items 
	 * @param orderId
	 * @return
	 */
	@RequestMapping(value="/get_item_list",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> itemList(Long orderId){
		Map<String, Object> ret = new HashMap<String, Object>();
		ret.put("rows", orderService.findOrderItemList(orderId));
		return ret;
	}
	
	/**
	 *  Edit order 
	 * @param order
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> edit(Order order){
		Map<String, Object> ret = new HashMap<String, Object>();
		if(order == null){
			ret.put("type", "error");
			ret.put("msg", " Please select the correct order information ");
			return ret;
		}
		if(StringUtils.isEmpty(order.getAddress())){
			ret.put("type", "error");
			ret.put("msg", " Please fill in the order receiving address ");
			return ret;
		}
		if(order.getMoney() == null){
			ret.put("type", "error");
			ret.put("msg", " Please fill in the order amount !");
			return ret;
		}
		if(orderService.edit(order) <= 0){
			ret.put("type", "error");
			ret.put("msg", " Edit failed , Please contact the Administrator !");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", " Edit success !");
		return ret;
	}
	
	
}

User management controller :

/**
 *  User management controller 
 *
 */
@RequestMapping("/admin/user")
@Controller
public class UserController {
	@Autowired
	private UserService userService;
	@Autowired
	private RoleService roleService;
	
	/**
	 *  User list page 
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/list",method=RequestMethod.GET)
	public ModelAndView list(ModelAndView model){
		Map<String, Object> queryMap = new HashMap<String, Object>();
		model.addObject("roleList", roleService.findList(queryMap));
		model.setViewName("user/list");
		return model;
	}
	
	/**
	 *  Get the list of users 
	 * @param page
	 * @param username
	 * @param roleId
	 * @param sex
	 * @return
	 */
	@RequestMapping(value="/list",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> getList(Page page,
			@RequestParam(name="username",required=false,defaultValue="") String username,
			@RequestParam(name="roleId",required=false) Long roleId,
			@RequestParam(name="sex",required=false) Integer sex,
			HttpServletRequest request
			){
		Map<String, Object> ret = new HashMap<String, Object>();
		Map<String, Object> queryMap = new HashMap<String, Object>();
		Role role = (Role) request.getSession().getAttribute("role");
		User user = (User) request.getSession().getAttribute("admin");
		if(role.getId().equals(Long.valueOf("2"))) {
			// If it's a seller role ,  You can only see your personal information 
			queryMap.put("Id", user.getId());
		}
		queryMap.put("username", username);
		queryMap.put("roleId", roleId);
		queryMap.put("sex", sex);
		queryMap.put("offset", page.getOffset());
		queryMap.put("pageSize", page.getRows());
		ret.put("rows", userService.findList(queryMap));
		ret.put("total", userService.getTotal(queryMap));
		return ret;
	}
	
	/**
	 *  Add users 
	 * @param user
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@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", " Please fill in the correct user information !");
			return ret;
		}
		if(StringUtils.isEmpty(user.getUsername())){
			ret.put("type", "error");
			ret.put("msg", " Please fill in the user name !");
			return ret;
		}
		if(StringUtils.isEmpty(user.getPassword())){
			ret.put("type", "error");
			ret.put("msg", " Please fill in the password !");
			return ret;
		}
		if(user.getRoleId() == null){
			ret.put("type", "error");
			ret.put("msg", " Please select the role !");
			return ret;
		}
		if(isExist(user.getUsername(), 0l)){
			ret.put("type", "error");
			ret.put("msg", " The user name already exists , Please re-enter !");
			return ret;
		}
		if(userService.add(user) <= 0){
			ret.put("type", "error");
			ret.put("msg", " User addition failed , Please contact the Administrator !");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", " Role added successfully !");
		return ret;
	}
	
	/**
	 *  Edit user 
	 * @param user
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, String> edit(User user){
		Map<String, String> ret = new HashMap<String, String>();
		if(user == null){
			ret.put("type", "error");
			ret.put("msg", " Please fill in the correct user information !");
			return ret;
		}
		if(StringUtils.isEmpty(user.getUsername())){
			ret.put("type", "error");
			ret.put("msg", " Please fill in the user name !");
			return ret;
		}
//		if(StringUtils.isEmpty(user.getPassword())){
//			ret.put("type", "error");
//			ret.put("msg", " Please fill in the password !");
//			return ret;
//		}
		if(user.getRoleId() == null){
			ret.put("type", "error");
			ret.put("msg", " Please select the role !");
			return ret;
		}
		if(isExist(user.getUsername(), user.getId())){
			ret.put("type", "error");
			ret.put("msg", " The user name already exists , Please re-enter !");
			return ret;
		}
		if(userService.edit(user) <= 0){
			ret.put("type", "error");
			ret.put("msg", " User addition failed , Please contact the Administrator !");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", " Role added successfully !");
		return ret;
	}
	
	/**
	 *  Bulk delete users 
	 * @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", " Select the data to delete !");
			return ret;
		}
		if(ids.contains(",")){
			ids = ids.substring(0,ids.length()-1);
		}
		if(userService.delete(ids) <= 0){
			ret.put("type", "error");
			ret.put("msg", " User deletion failed , Please contact the Administrator !");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", " User delete successful !");
		return ret;
	}
	
	/**
	 *  To upload pictures 
	 * @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", " Select the file to upload !");
			return ret;
		}
		if(photo.getSize() > 1024*1024*1024){
			ret.put("type", "error");
			ret.put("msg", " The file size cannot exceed 10M!");
			return ret;
		}
		// Get file suffix 
		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", " Please select jpg,jpeg,gif,png Format picture !");
			return ret;
		}
		String savePath = request.getServletContext().getRealPath("/") + "/resources/upload/";
		File savePathFile = new File(savePath);
		if(!savePathFile.exists()){
			// If it doesn't exist, change the directory , Create directory 
			savePathFile.mkdir();
		}
		String filename = new Date().getTime()+"."+suffix;
		try {
			// Save the file to the specified directory 
			photo.transferTo(new File(savePath+filename));
		}catch (Exception e) {
			// TODO Auto-generated catch block
			ret.put("type", "error");
			ret.put("msg", " Save file exception !");
			e.printStackTrace();
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", " User delete successful !");
		ret.put("filepath",request.getServletContext().getContextPath() + "/resources/upload/" + filename );
		return ret;
	}
	/**
	 *  Determine whether the user name exists 
	 * @param username
	 * @param id
	 * @return
	 */
	private boolean isExist(String username,Long id){
		User user = userService.findByUsername(username);
		if(user == null)return false;
		if(user.getId().longValue() == id.longValue())return false;
		return true;
	}
}

System operation controller :

/**
 *  System operation controller 
 * @author yy
 *
 */
@Controller
@RequestMapping("/system")
public class SystemController {
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private RoleService roleService;
	
	@Autowired
	private AuthorityService authorityService;
	
	@Autowired
	private MenuService menuService;
	
	@Autowired
	private LogService logService;
	
	/**
	 *  Home page after system login 
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/index",method=RequestMethod.GET)
	public ModelAndView index(ModelAndView model,HttpServletRequest request){
		List<Menu> userMenus = (List<Menu>)request.getSession().getAttribute("userMenus");
		model.addObject("topMenuList", MenuUtil.getAllTopMenu(userMenus));
		model.addObject("secondMenuList", MenuUtil.getAllSecondMenu(userMenus));
		model.setViewName("system/index");
		return model;//WEB-INF/views/+system/index+.jsp = WEB-INF/views/system/index.jsp
	}
	
	/**
	 *  Welcome page after system login 
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/welcome",method=RequestMethod.GET)
	public ModelAndView welcome(ModelAndView model){
		model.setViewName("system/welcome");
		return model;
	}
	
	/**
	 *  System 500 Error page 
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/operation_error",method=RequestMethod.GET)
	public ModelAndView operationError(ModelAndView model){
		model.setViewName("errors/500");
		return model;
	}
	
	
	/**
	 *  Landing page 
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/login",method=RequestMethod.GET)
	public ModelAndView login(ModelAndView model){
		model.setViewName("system/login");
		return model;
	}
	
	/**
	 *  Login form submission processing controller 
	 * @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", " Please fill in the user information !");
			return ret;
		}
		if(StringUtils.isEmpty(cpacha)){
			ret.put("type", "error");
			ret.put("msg", " Please fill in the verification code !");
			return ret;
		}
		if(StringUtils.isEmpty(user.getUsername())){
			ret.put("type", "error");
			ret.put("msg", " Please fill in the user name !");
			return ret;
		}
		if(StringUtils.isEmpty(user.getPassword())){
			ret.put("type", "error");
			ret.put("msg", " Please fill in the password !");
			return ret;
		}
		Object loginCpacha = request.getSession().getAttribute("loginCpacha");
		if(loginCpacha == null){
			ret.put("type", "error");
			ret.put("msg", " session time out , Please refresh the page !");
			return ret;
		}
		if(!cpacha.toUpperCase().equals(loginCpacha.toString().toUpperCase())){
			ret.put("type", "error");
			ret.put("msg", " Verification code error !");
			logService.add(" The user is called "+user.getUsername()+" The user entered the verification code incorrectly when logging in !");
			return ret;
		}
		User findByUsername = userService.findByUsername(user.getUsername());
		if(findByUsername == null){
			ret.put("type", "error");
			ret.put("msg", " The user name does not exist !");
			logService.add(" Login time , The user is called "+user.getUsername()+" The user does not exist !");
			return ret;
		}
		if(!user.getPassword().equals(findByUsername.getPassword())){
			ret.put("type", "error");
			ret.put("msg", " Wrong password !");
			logService.add(" The user is called "+user.getUsername()+" The user entered the wrong password when logging in !");
			return ret;
		}
		// The user name, password and verification code are correct 
		// At this time, you need to query the user's role permissions 
		Role role = roleService.find(findByUsername.getRoleId());
		List<Authority> authorityList = authorityService.findListByRoleId(role.getId());// Get permission list according to role 
		String menuIds = "";
		for(Authority authority:authorityList){
			menuIds += authority.getMenuId() + ",";
		}
		if(!StringUtils.isEmpty(menuIds)){
			menuIds = menuIds.substring(0,menuIds.length()-1);
		}
		List<Menu> userMenus = menuService.findListByIds(menuIds);
		// Put role information 、 Put the menu information in session in 
		request.getSession().setAttribute("admin", findByUsername);
		request.getSession().setAttribute("role", role);
		request.getSession().setAttribute("userMenus", userMenus);
		ret.put("type", "success");
		ret.put("msg", " Login successful !");
		logService.add(" The user is called {"+user.getUsername()+"}, The role of {"+role.getName()+"} User login succeeded !");
		return ret;
	}
	
	/**
	 *  Background exit logout function 
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/logout",method=RequestMethod.GET)
	public String logout(HttpServletRequest request){
		HttpSession session = request.getSession();
		session.setAttribute("admin", null);
		session.setAttribute("role", null);
		request.getSession().setAttribute("userMenus", null);
		return "redirect:login";
	}
	
	/**
	 *  Change password page 
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/edit_password",method=RequestMethod.GET)
	public ModelAndView editPassword(ModelAndView model){
		model.setViewName("system/edit_password");
		return model;
	}
	
	@RequestMapping(value="/edit_password",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, String> editPasswordAct(String newpassword,String oldpassword,HttpServletRequest request){
		Map<String, String> ret = new HashMap<String, String>();
		if(StringUtils.isEmpty(newpassword)){
			ret.put("type", "error");
			ret.put("msg", " Please fill in your new password !");
			return ret;
		}
		User user = (User)request.getSession().getAttribute("admin");
		if(!user.getPassword().equals(oldpassword)){
			ret.put("type", "error");
			ret.put("msg", " The original password is wrong !");
			return ret;
		}
		user.setPassword(newpassword);
		if(userService.editPassword(user) <= 0){
			ret.put("type", "error");
			ret.put("msg", " Password change failed , Please contact the Administrator !");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", " Password changed successfully !");
		logService.add(" The user is called {"+user.getUsername()+"}, The user of successfully changed the password !");
		return ret;
	} 
	
	/**
	 *  This method is adopted for all verification codes of the system 
	 * @param vcodeLen
	 * @param width
	 * @param height
	 * @param cpachaType: Used to distinguish the type of verification code , Incoming string 
	 * @param request
	 * @param response
	 */
	@RequestMapping(value="/get_cpacha",method=RequestMethod.GET)
	public void generateCpacha(
			@RequestParam(name="vl",required=false,defaultValue="4") Integer vcodeLen,
			@RequestParam(name="w",required=false,defaultValue="100") Integer width,
			@RequestParam(name="h",required=false,defaultValue="30") Integer height,
			@RequestParam(name="type",required=true,defaultValue="loginCpacha") String cpachaType,
			HttpServletRequest request,
			HttpServletResponse response){
		CpachaUtil cpachaUtil = new CpachaUtil(vcodeLen, width, height);
		String generatorVCode = cpachaUtil.generatorVCode();
		request.getSession().setAttribute(cpachaType, generatorVCode);
		BufferedImage generatorRotateVCodeImage = cpachaUtil.generatorRotateVCodeImage(generatorVCode, true);
		try {
			ImageIO.write(generatorRotateVCodeImage, "gif", response.getOutputStream());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

copyright notice
author[qq_ one billion three hundred and thirty-four million six hundr],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270507201865.html

Random recommended