current position:Home>Java project: sporting goods Mall (java + springboot + jsp + HTML + Maven + MySQL)

Java project: sporting goods Mall (java + springboot + jsp + HTML + Maven + MySQL)

2022-04-29 05:55:36pastclouds

The source code for : Blog's front page " resources " Download !

Project introduction

This project is a front and back office management system , Including administrator and ordinary user ;
The administrator role includes the following functions :
Administrator login , User management , Commodity type management , Commodity management , Order information management , User message management , Information management and other functions .

User roles include the following functions :
User home page , The user login , recommendation , Information information , Message board , Check products , place order , View order information , Personal data management and other functions .

ps: The recommendation module uses collaborative filtering recommendation algorithm , The order module uses Baidu map api. This mall can be modified to any mall, not just a sports mall .

Environmental needs

1. Running environment : It is best to java jdk 1.8, We run on this platform . Other versions can, in theory .
2.IDE Environmental Science :IDEA,Eclipse,Myeclipse Fine . recommend IDEA;
3.tomcat Environmental Science :Tomcat 7.x,8.x,9.x All versions are available
4. Hardware environment :windows 7/8/10 1G Above memory ; perhaps Mac OS;

5. database :MySql 5.7 edition ;

6. whether Maven project : yes ;

Technology stack

1. Back end :SpringBoot

2. front end :HTML+JSP+CSS+JavaScript+jQuery

Instructions

1. Use Navicat Or other tools , stay mysql Create a database with the corresponding name in , And import the sql file ;
2. Use IDEA/Eclipse/MyEclipse Import the project ,Eclipse/MyEclipse Import time , if maven Item, please select maven;
if maven project , After importing successfully, please execute maven clean;maven install command , And then run ;
3. In the project application.properties Change the database configuration in the configuration file to your own configuration ;
4. Run the project , Enter... In the browser http://localhost:8110/ Sign in
Administrator account / password :admin/admin
The user account / password : user/123456

 

 

 

 

 

 

 

User related interfaces :

/**
 *  User related interfaces 
 */
@Controller
@RequestMapping("/index")
public class UserController{
	
	@Resource
	private UserService userService;
	@Resource
	private GoodService goodService;
	@Resource
	private OrderService orderService;
	@Resource
	private CartService cartService;

	
	/**
	 *  User registration 
	 * @return
	 */
	@GetMapping("/register")
	public String reg() {
		return "/index/register.jsp";
	}
	
	/**
	 *  User registration 
	 * @return
	 */
	@PostMapping("/register")
	public String register(Users user, HttpServletRequest request){
		if (user.getUsername().isEmpty()) {
			request.setAttribute("msg", " The username cannot be empty !");
		}else if (Objects.nonNull(userService.getByUsername(user.getUsername()))) {
			request.setAttribute("msg", " User name already exists !");
		}else {
			userService.add(user);
			request.setAttribute("msg", " Registered successfully   You can log in !");
			return "/index/login.jsp";
		}
		return "/index/register.jsp";
	}
	
	/**
	 *  The user login 
	 * @return
	 */
	@GetMapping("/login")
	public String log() {
		return "/index/login.jsp";
	}
	
	/**
	 *  The user login 
	 * @return
	 */
	@PostMapping("/login")
	public String login(Users user, HttpServletRequest request, HttpSession session) {
		Users loginUser = userService.getByUsernameAndPassword(user.getUsername(), user.getPassword());
		if (Objects.isNull(loginUser)) {
			request.setAttribute("msg", " Wrong user name or password ");
			return "/index/login.jsp";
		}
		session.setAttribute("user", loginUser);
		//  Restore shopping cart 
		session.setAttribute("cartCount", cartService.getCount(loginUser.getId()));
		String referer = request.getHeader("referer"); //  Source page 
		System.out.println(referer); //TODO
		return "redirect:index";
	}

	/**
	 *  Sign out 
	 * @return
	 */
	@GetMapping("/logout")
	public String logout(HttpSession session) {
		session.removeAttribute("user");
		session.removeAttribute("cartCount");
		return "/index/login.jsp";
	}

	/**
	 *  Look at the points 
	 */
	@GetMapping("/mypoint")
	public String mypoint() {
		return "/index/mypoint.jsp";
	}

	// Integral recharge 
	@RequestMapping("/addPoint")
	public String addPoint(double point,HttpSession session,HttpServletRequest request){
		Users users = (Users)session.getAttribute("user");
		BigDecimal bigDecimal = new BigDecimal(Double.toString(point)).add(new BigDecimal(Double.toString(users.getPoint())));
		users.setPoint(bigDecimal.doubleValue());
		int count = userService.updatePoint(users);
		if(count > 0){
			session.setAttribute("user",users);
			request.setAttribute("msg"," Recharge successful !");
		}else{
			request.setAttribute("msg"," Recharge failed !");
		}
		return "/index/mypoint.jsp";
	}

	/**
	 *  Check out the shopping cart 
	 * @return
	 */
	@GetMapping("/cart")
	public String cart(HttpServletRequest request, HttpSession session) {
		Users user = (Users) session.getAttribute("user");
		request.setAttribute("cartList", cartService.getList(user.getId()));
		request.setAttribute("cartCount", cartService.getCount(user.getId()));
		request.setAttribute("cartTotal", cartService.getTotal(user.getId()));
		return "/index/cart.jsp";
	}
	
	/**
	 *  Total amount of shopping cart 
	 * @return
	 */
	@GetMapping("/cartTotal")
	public @ResponseBody int cartTotal(HttpSession session){
		Users user = (Users) session.getAttribute("user");
		return cartService.getTotal(user.getId());
	}
	
	/**
	 *  Add to cart 
	 * @return
	 */
	@PostMapping("/cartBuy")
	public @ResponseBody boolean cartBuy(int goodId, HttpSession session){
		Users user = (Users) session.getAttribute("user");
		return cartService.save(goodId, user.getId());
	}
	
	/**
	 *  Add quantity 
	 */
	@PostMapping("/cartAdd")
	public @ResponseBody boolean cartAdd(int id){
		return cartService.add(id);
	}
	
	/**
	 *  Reduce the quantity 
	 */
	@PostMapping("/cartLess")
	public @ResponseBody boolean cartLess(int id){
		return cartService.less(id);
	}
	
	/**
	 *  Delete 
	 */
	@PostMapping("/cartDelete")
	public @ResponseBody boolean cartDelete(int id){
		return cartService.delete(id);
	}

	
	/**
	 *  Check the order 
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	@GetMapping("/order")
	public String order(HttpServletRequest request, HttpSession session,
			@RequestParam(required=false, defaultValue="1")int page, 
			@RequestParam(required=false, defaultValue="6")int size) throws UnsupportedEncodingException{
		Users user = (Users) session.getAttribute("user");
		request.setAttribute("orderList", orderService.getListByUserid(user.getId(), page, size));
		request.setAttribute("pageHtml", PageUtil.getPageHtml(request, orderService.getCountByUserid(user.getId()), page, size));
		return "/index/order.jsp";
	}
	
	/**
	 *  Direct purchase 
	 * @return
	 * @throws MyException 
	 */
	@PostMapping("/orderAdd")
	public String orderAdd(int goodId, HttpSession session) throws MyException{
		Users user = (Users) session.getAttribute("user");
		int orderId = orderService.add(goodId, user.getId());
		return "redirect:orderPay?id="+orderId; //  Jump payment 
	}
	
	/**
	 *  Shopping cart checkout 
	 * @return
	 * @throws MyException 
	 */
	@GetMapping("/orderSave")
	public String orderSave(ServletRequest request, HttpSession session) throws MyException{
		Users user = (Users) session.getAttribute("user");
		int orderId = orderService.save(user.getId());
		session.removeAttribute("cartCount"); //  Clean up the shopping cart session
		return "redirect:orderPay?id="+orderId; //  Jump payment 
	}
	
	/**
	 *  Payment page 
	 * @return
	 */
	@GetMapping("/orderPay")
	public String orderPay(int id, ServletRequest request) {
		request.setAttribute("order", orderService.get(id));
		return "/index/pay.jsp";
	}
	
	/**
	 *  payment ( simulation )
	 * @return
	 */
	@PostMapping("/orderPay")
	@ResponseBody
	public int orderPay(Orders order,HttpSession session) {
		Users users = (Users) session.getAttribute("user");
		BigDecimal bigDecimal = new BigDecimal(0);
		if(order.getPaytype() == Orders.PAYTYPE_OFFLINE){// When paying for points 
			double d1 = order.getTotal();// Commodity price 
			if(users.getPoint().compareTo(d1) < 0){
				return -1;
			}else{
				// Total points  =  User points  -  Deduction points 
				bigDecimal = new BigDecimal(Double.toString(users.getPoint())).subtract(new BigDecimal(Double.toString(d1)));
			}
		}else{
			double d2 = order.getTotal()/100;// Points earned by purchasing goods 
			// Total points  =  User points  +  Acquired 
			bigDecimal = new BigDecimal(Double.toString(users.getPoint())).add(new BigDecimal(Double.toString(d2)));
		}
		users.setPoint(bigDecimal.doubleValue());// Save points 
		int count = userService.updatePoint(users);
		if(count > 0){
			session.setAttribute("user",users);// Update user points 
		}
		orderService.pay(order);
		return 1;
	}
	
	
	/**
	 *  Shipping address 
	 * @return
	 */
	@GetMapping("/address")
	public String address(){ //  Use session Data in 
		return "/index/address.jsp";
	}
	
	/**
	 *  Modify the information 
	 * @return
	 */
	@PostMapping("/addressUpdate")
	public String addressUpdate(String name, String phone, String address, HttpServletRequest request, HttpSession session){
		Users user = (Users) session.getAttribute("user");
		userService.update(user.getId(), name, phone, address);  //  Update the database 
		session.setAttribute("user", userService.get(user.getId())); //  to update session
		request.setAttribute("msg", " The information was modified successfully !");
		return "/index/address.jsp";
	}
	
	/**
	 *  Shipping address 
	 * @return
	 */
	@GetMapping("/password")
	public String password(){ //  Use session Data in 
		return "/index/password.jsp";
	}
	
	/**
	 *  Change Password 
	 * @return
	 */
	@PostMapping("/passwordUpdate")
	public String passwordUpdate(String password, String passwordNew, HttpServletRequest request, HttpSession session){
		Users user = (Users) session.getAttribute("user");
		user = userService.get(user.getId());
		if(!user.getPassword().equals(SafeUtil.encode(password))) {
			request.setAttribute("msg", " The original password is wrong !");
		}else {
			userService.updatePassword(user.getId(), passwordNew);
			request.setAttribute("msg", " Password changed successfully !");
		}
		return "/index/password.jsp";
	}
	
	/*
	 *  User confirms receipt 
	 */
	@RequestMapping("/userfinish")
	public String userFinish(int id, byte status,
			@RequestParam(required=false, defaultValue="1") int page) {
		orderService.finish(id);
		return "redirect:order?page="+page;
	}
}

Background management interface :

/**
 *  Background management interface 
 */
@Controller
@RequestMapping("/admin")
public class AdminController {

	@Autowired
	private AdminService adminService;
	@Autowired
	private OrderService orderService;
	@Autowired
	private UserService userService;
	@Autowired
	private GoodService goodService;
	@Autowired
	private TopService topService;
	@Autowired
	private TypeService typeService;

	/**
	 *  Administrator login  ( logic )
	 * @return
	 */
	@GetMapping("/login")
	public String log() {
		return "/admin/login.jsp";
	}
	
	/**
	 *  Administrator login 
	 * @return
	 */
	@PostMapping("/login")
	public String login(String username, String password, 
			HttpServletRequest request, HttpSession session) {
		Admins admin = adminService.getByUsernameAndPassword(username, password);
		if (Objects.nonNull(admin)) {
			session.setAttribute("admin", admin);
			return "redirect:index";
		}
		request.setAttribute("msg", " Wrong user name or password !");
		return "/admin/login.jsp";
	}

	/**
	 *  sign out 
	 * @return
	 */
	@GetMapping("/logout")
	public String logout(HttpSession session) {
		session.removeAttribute("admin");
		return "/admin/login.jsp";
	}
	
	/**
	 *  The background page 
	 * @return
	 */
	@GetMapping("/index")
	public String index(HttpServletRequest request) {
		request.setAttribute("msg", " congratulations !  Login succeeded ");
		return "/admin/index.jsp";
	}

	/**
	 *  Category list 
	 * @return
	 */
	@GetMapping("/typeList")
	public String typeList(HttpServletRequest request) {
		request.setAttribute("flag", 1);
		request.setAttribute("typeList", typeService.getList());
		return "/admin/type_list.jsp";
	}

	/**
	 *  Category add 
	 * @return
	 */
	@GetMapping("/typeAdd")
	public String typeAdd(HttpServletRequest request) {
		request.setAttribute("flag", 1);
		return "/admin/type_add.jsp";
	}
	
	/**
	 *  Category add 
	 * @return
	 * @throws Exception 
	 */
	@PostMapping("/typeSave")
	public String typeSave(Types type) throws Exception {
		typeService.add(type);
		return "redirect:typeList?flag=1";
	}

	/**
	 *  Category update 
	 * @return
	 */
	@GetMapping("/typeEdit")
	public String typeEdit(int id, HttpServletRequest request) {
		request.setAttribute("flag", 1);
		request.setAttribute("type", typeService.get(id));
		return "/admin/type_edit.jsp";
	}

	/**
	 *  Category update 
	 * @return
	 * @throws Exception 
	 */
	@PostMapping("/typeUpdate")
	public String typeUpdate(Types type) throws Exception {
		typeService.update(type);
		return "redirect:typeList?flag=1";
	}

	/**
	 *  Category deleted 
	 * @return
	 */
	@GetMapping("/typeDelete")
	public String typeDelete(int id) {
		typeService.delete(id);
		return "redirect:typeList?flag=1";
	}

	/**
	 *  Product list 
	 * @return
	 */
	@GetMapping("/goodList")
	public String goodList(HttpServletRequest request, 
			@RequestParam(required=false, defaultValue="0") byte type,
			@RequestParam(required=false, defaultValue="1") int page,
			@RequestParam(required=false, defaultValue="10") int size) {
		request.setAttribute("flag", 2);
		request.setAttribute("page", page);
		request.setAttribute("type", type);
		if(type > 0) {
			String goodIds = topService.getGoodIdsByType(type);
			request.setAttribute("goodList", goodService.getListByIds(goodIds, page, size));
			request.setAttribute("pageTool", PageUtil.getPageTool(request, goodService.getCountByIds(goodIds), page, size));
		}else {
			request.setAttribute("goodList", goodService.getList(page, size));
			request.setAttribute("pageTool", PageUtil.getPageTool(request, goodService.getCount(), page, size));
		}
		return "/admin/good_list.jsp";
	}

	/**
	 *  Product add 
	 * @return
	 */
	@GetMapping("/goodAdd")
	public String goodAdd(HttpServletRequest request) {
		request.setAttribute("flag", 2);
		request.setAttribute("typeList", typeService.getList());
		return "/admin/good_add.jsp";
	}

	/**
	 *  Product add 
	 * @return
	 * @throws Exception 
	 */
	@PostMapping("/goodSave")
	public String goodSave(Goods good, MultipartFile file,
			@RequestParam(required=false, defaultValue="1") int page) throws Exception {
		good.setCover(UploadUtil.upload(file));
		goodService.add(good);
		return "redirect:goodList?flag=2&page="+page;
	}

	/**
	 *  Product updates 
	 * @return
	 */
	@GetMapping("/goodEdit")
	public String goodEdit(int id, HttpServletRequest request) {
		request.setAttribute("flag", 2);
		request.setAttribute("typeList", typeService.getList());
		request.setAttribute("good", goodService.get(id));
		return "/admin/good_edit.jsp";
	}

	/**
	 *  Product updates 
	 * @return
	 * @throws Exception 
	 */
	@PostMapping("/goodUpdate")
	public String goodUpdate(Goods good, MultipartFile file, 
			@RequestParam(required=false, defaultValue="1") int page) throws Exception {
		if (Objects.nonNull(file) && !file.isEmpty()) {
			good.setCover(UploadUtil.upload(file));
		}
		goodService.update(good);
		return "redirect:goodList?flag=2&page="+page;
	}

	/**
	 *  Product deletion 
	 * @return
	 */
	@GetMapping("/goodDelete")
	public String goodDelete(int id, 
			@RequestParam(required=false, defaultValue="1") int page) {
		goodService.delete(id);
		return "redirect:goodList?flag=2&page="+page;
	}
	
	/**
	 *  Add recommendations 
	 * @return
	 */
	@PostMapping("/topSave")
	public @ResponseBody String topSave(int goodId, byte type) {
		return topService.add(goodId, type) ? "ok" : null;
	}
	
	/**
	 *  Delete recommendation 
	 * @return
	 */
	@PostMapping("/topDelete")
	public @ResponseBody String topDelete(int goodId, byte type) {
		return topService.delete(goodId, type) ? "ok" : null;
	}

	/**
	 *  Order list 
	 * @return
	 */
	@GetMapping("/orderList")
	public String orderList(HttpServletRequest request,
			@RequestParam(required=false, defaultValue="0")byte status, 
			@RequestParam(required=false, defaultValue="1") int page, 
			@RequestParam(required=false, defaultValue="10") int size) {
		request.setAttribute("flag", 3);
		request.setAttribute("status", status);
		request.setAttribute("orderList", orderService.getList(status, page, size));
		request.setAttribute("pageTool", PageUtil.getPageTool(request, orderService.getCount(status), page, size));
		return "/admin/order_list.jsp";
	}

	/**
	 *  Order delivery 
	 * @return
	 */
	@GetMapping("/orderSend")
	public String orderSend(int id, byte status,
			@RequestParam(required=false, defaultValue="1") int page) {
		orderService.send(id);
		return "redirect:orderList?flag=3&status="+status+"&page="+page;
	}
	
	/**
	 *  Order complete 
	 * @return
	 */
	@GetMapping("/orderFinish")
	public String orderFinish(int id, byte status,
			@RequestParam(required=false, defaultValue="1") int page) {
		orderService.finish(id);
		return "redirect:orderList?flag=3&status="+status+"&page="+page;
	}

	/**
	 *  Order deletion 
	 * @return
	 */
	@GetMapping("/orderDelete")
	public String orderDelete(int id, byte status,
			@RequestParam(required=false, defaultValue="1") int page) {
		orderService.delete(id);
		return "redirect:orderList?flag=3&status="+status+"&page="+page;
	}

	/**
	 *  Customer management 
	 * @return
	 */
	@GetMapping("/userList")
	public String userList(HttpServletRequest request,
			@RequestParam(required=false, defaultValue="1") int page, 
			@RequestParam(required=false, defaultValue="10") int size) {
		request.setAttribute("flag", 4);
		request.setAttribute("userList", userService.getList(page, size));
		request.setAttribute("pageTool", PageUtil.getPageTool(request, userService.getCount(), page, size));
		return "/admin/user_list.jsp";
	}

	/**
	 *  Customer addition 
	 * @return
	 */
	@GetMapping("/userAdd")
	public String userAdd(HttpServletRequest request) {
		request.setAttribute("flag", 4);
		return "/admin/user_add.jsp";
	}

	/**
	 *  Customer addition 
	 * @return
	 */
	@PostMapping("/userSave")
	public String userSave(Users user, HttpServletRequest request, 
			@RequestParam(required=false, defaultValue="1") int page) {
		if (Objects.nonNull(userService.getByUsername(user.getUsername()))) {
			request.setAttribute("msg", " User name already exists !");
			return "/admin/user_add.jsp";
		}
		userService.add(user);
		return "redirect:userList?flag=4&page="+page;
	}

	/**
	 *  Customer password reset page 
	 * @return
	 */
	@GetMapping("/userRe")
	public String userRe(int id, HttpServletRequest request) {
		request.setAttribute("flag", 4);
		request.setAttribute("user", userService.get(id));
		return "/admin/user_reset.jsp";
	}

	/**
	 *  Customer password reset 
	 * @return
	 */
	@PostMapping("/userReset")
	public String userReset(int id, String password, 
			@RequestParam(required=false, defaultValue="1") int page) {
		userService.updatePassword(id, password);
		return "redirect:userList?page="+page;
	}

	/**
	 *  Customer updates 
	 * @return
	 */
	@GetMapping("/userEdit")
	public String userEdit(int id, HttpServletRequest request) {
		request.setAttribute("flag", 4);
		request.setAttribute("user", userService.get(id));
		return "/admin/user_edit.jsp";
	}

	/**
	 *  Customer updates 
	 * @return
	 */
	@PostMapping("/userUpdate")
	public String userUpdate(int id, String name, String phone, String address, 
			@RequestParam(required=false, defaultValue="1") int page) {
		userService.update(id, name, phone, address);
		return "redirect:userList?flag=4&page="+page;
	}

	/**
	 *  Customer delete 
	 * @return
	 */
	@GetMapping("/userDelete")
	public String userDelete(int id, 
			@RequestParam(required=false, defaultValue="1") int page) {
		userService.delete(id);
		return "redirect:userList?flag=4&page="+page;
	}

	/**
	 *  Admin list 
	 * @return
	 */
	@GetMapping("/adminList")
	public String adminList(HttpServletRequest request, 
			@RequestParam(required=false, defaultValue="1") int page, 
			@RequestParam(required=false, defaultValue="10") int size) {
		request.setAttribute("flag", 5);
		request.setAttribute("adminList", adminService.getList(page, size));
		request.setAttribute("pageTool", PageUtil.getPageTool(request, adminService.getCount(), page, size));
		return "/admin/admin_list.jsp";
	}

	/**
	 *  Administrators add 
	 * @return
	 */
	@GetMapping("/adminAdd")
	public String adminAdd(HttpServletRequest request) {
		request.setAttribute("flag", 5);
		return "/admin/admin_add.jsp";
	}
	
	/**
	 *  Administrator password reset 
	 * @return
	 */
	@GetMapping("/adminRe")
	public String adminRe(int id, HttpServletRequest request) {
		request.setAttribute("flag", 5);
		request.setAttribute("admin", adminService.get(id));
		return "/admin/admin_reset.jsp";
	}

	/**
	 *  Administrator password reset 
	 * @return
	 */
	@PostMapping("/adminReset")
	public String adminReset(int id, String password, HttpServletRequest request,
			@RequestParam(required=false, defaultValue="1") int page) {
		adminService.update(id, password);
		return "redirect:adminList?page="+page;
	}

	/**
	 *  Administrators add 
	 * @return
	 */
	@PostMapping("/adminSave")
	public String adminSave(Admins admin, HttpServletRequest request, 
			@RequestParam(required=false, defaultValue="1") int page) {
		if (Objects.nonNull(adminService.getByUsername(admin.getUsername()))) {
			request.setAttribute("msg", " User name already exists !");
			return "/admin/admin_add.jsp";
		}
		adminService.add(admin);
		return "redirect:adminList?flag=5&page="+page;
	}

	/**
	 *  Administrator delete 
	 * @return
	 */
	@GetMapping("/adminDelete")
	public String adminDelete(int id, 
			@RequestParam(required=false, defaultValue="1") int page) {
		adminService.delete(id);
		return "redirect:adminList?flag=5&page="+page;
	}
	
    /**
     *  Image upload 
     * @throws Exception 
     */
    @PostMapping("upload")
    public @ResponseBody Map<String, Object> upload(MultipartFile imgFile) throws Exception {
    	Map<String, Object> map = new HashMap<>();
    	if (Objects.nonNull(imgFile) && !imgFile.isEmpty()) {
    		map.put("error", 0);
    		map.put("url", UploadUtil.upload(imgFile));
    		return map;
		}else {
			map.put("error", 1);
			map.put("message", " Upload error ");
		}
    	return map;
    }

	/**
	 *  Order export 
	 */
	@RequestMapping("orderExportExcel")
	public void orderExportExcel(HttpServletResponse response){
		// Export all orders 
		List<Orders> orderList = orderService.getAllList();
		for(Orders orders : orderList){
			if(orders.getAddress() != null && !"".equals(orders.getAddress())){
				StringBuffer buf=new StringBuffer();
				buf.append(orders.getName()+"\n"+orders.getPhone()+"\n"+orders.getAddress());
				orders.setAddress(buf.toString());
			}
			if(orders.getStatus() == Orders.STATUS_UNPAY){
				orders.setName(" Unpaid ");
			}else if(orders.getStatus() == Orders.STATUS_PAYED){
				orders.setName(" Paid ");
			}else if(orders.getStatus() == Orders.PAYTYPE_OFFLINE){
				orders.setName(" In delivery ");
			}else{
				orders.setName(" Completed ");
			}
			if(orders.getPaytype() == Orders.PAYTYPE_WECHAT){
				orders.setPhone(" WeChat ");
			}else if(orders.getPaytype() == Orders.PAYTYPE_ALIPAY){
				orders.setPhone(" Alipay ");
			}else{
				orders.setPhone(" integral ");
			}
			StringBuffer buf1=new StringBuffer();
			orders.setUsername(orders.getUser().getName());
			for(Items items : orders.getItemList()){
				buf1.append(items.getGood().getName() + " *" + items.getAmount() + "\n");
			}
			orders.setDingdanInfo(buf1.toString());
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			String export=" The order no. #id, Order amount #total, Goods details #dingdanInfo, Receiving information #address, The order status #name, Method of payment #phone, Buying users #username";// Here is the title ,excel First line title, Follow this format , The format does not need to be changed , But you can add or reduce items .
			String[] excelHeader = export.split(",");
			String fileName=" Order " + sdf.format(new Date()); //className: Generated excel Default file name and sheet page 
			ExcelUtils.export(response, fileName, excelHeader, orderList);// Call the encapsulated export method , The specific methods are as follows 
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

Front desk related interface : 

/**
 *  Front desk related interface 
 */
@Controller
@RequestMapping("/index")
public class IndexController{
	
	@Autowired
	private GoodService goodService;
	@Autowired
	private TypeService typeService;
	

	/**
	 *  home page 
	 * @return
	 */
	@GetMapping("/index")
	public String index(HttpServletRequest request){
		request.setAttribute("flag", 1);
		//  Recommended today 
		List<Goods> todayList = goodService.getListByTopType(Tops.TYPE_TODAY, 1, 6); //  Take before 6 individual 
		request.setAttribute("todayList", todayList);
		//  Top sellers 
		List<Goods> hotList = goodService.getListOrderSales(1, 10); //  Take before 10 individual 
		request.setAttribute("hotList", hotList);
		//  Category list 
		List<Types> typeList = typeService.getList();
		List<Map<String, Object>> dataList = new ArrayList<>();
		for(Types type : typeList) {
			Map<String, Object> map = new HashMap<>();
			map.put("type", type);
			map.put("goodList", goodService.getListByType(type.getId(), 1, 15)); //  Take before 15 individual 
			dataList.add(map);
		}
		request.setAttribute("dataList", dataList);
		return "/index/index.jsp";
	}
	
	/**
	 *  Classification of goods 
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	@GetMapping("/type")
	public String type(HttpServletRequest request, 
			@RequestParam(required=false, defaultValue="0")int id, 
			@RequestParam(required=false, defaultValue="1")int page, 
			@RequestParam(required=false, defaultValue="10")int size) throws UnsupportedEncodingException {
		request.setAttribute("type", typeService.get(id));
		request.setAttribute("goodList", goodService.getListByType(id, page, size));
		request.setAttribute("pageHtml", PageUtil.getPageHtml(request, goodService.getCountByType(id), page, size));
		return "/index/goods.jsp";
	}
	
	/**
	 *  Recommended today 
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	@GetMapping("/today")
	public String today(HttpServletRequest request, 
			@RequestParam(required=false, defaultValue="1")int page, 
			@RequestParam(required=false, defaultValue="10")int size) throws UnsupportedEncodingException {
		request.setAttribute("flag", 2);
		request.setAttribute("goodList", goodService.getListByTopType(Tops.TYPE_TODAY, page, size));
		request.setAttribute("pageHtml", PageUtil.getPageHtml(request, goodService.getCountByTopType(Tops.TYPE_TODAY), page, size));
		return "/index/goods.jsp";
	}
	
	/**
	 *  Recommended sale 
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	@GetMapping("/hot")
	public String hot(HttpServletRequest request, 
			@RequestParam(required=false, defaultValue="1")int page, 
			@RequestParam(required=false, defaultValue="10")int size) throws UnsupportedEncodingException{
		request.setAttribute("flag", 3);
		request.setAttribute("goodList", goodService.getListOrderSales(page, size));
		request.setAttribute("pageHtml", PageUtil.getPageHtml(request, goodService.getCount(), page, size));
		return "/index/goods.jsp";
	}
	
	/**
	 *  new arrival 
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	@GetMapping("/new")
	public String news(HttpServletRequest request, 
			@RequestParam(required=false, defaultValue="1")int page, 
			@RequestParam(required=false, defaultValue="10")int size) throws UnsupportedEncodingException{
		request.setAttribute("flag", 4);
		request.setAttribute("goodList", goodService.getList(page, size));
		request.setAttribute("pageHtml", PageUtil.getPageHtml(request, goodService.getCount(), page, size));
		return "/index/goods.jsp";
	}
	
	/**
	 *  Search for 
	 * @return
	 */
	@GetMapping("/search")
	public String search(String search, HttpServletRequest request, 
			@RequestParam(required=false, defaultValue="1")int page, 
			@RequestParam(required=false, defaultValue="10")int size) throws UnsupportedEncodingException {
		search = new String(search.getBytes("ISO8859-1"),"utf-8");
		request.setAttribute("search", search);
		System.out.println(search);
		if (Objects.nonNull(search) && !search.trim().isEmpty()) {
			request.setAttribute("goodList", goodService.getListByName(search, page, size));
			request.setAttribute("pageHtml", PageUtil.getPageHtml(request, goodService.getTotalByName(search), page, size));
		}
		return "/index/goods.jsp";
	}
	
	/**
	 *  Goods details 
	 * @return
	 */
	@GetMapping("/detail")
	public String detail(int id, HttpServletRequest request){
		request.setAttribute("good", goodService.get(id));
		//  Today I recommend the first two   Show... On the details page 
		request.setAttribute("todayList", goodService.getListByTopType(Tops.TYPE_TODAY, 1, 2));
		return "/index/detail.jsp";
	}

}

 

  The source code for : Blog's front page " resources " Download !

copyright notice
author[pastclouds],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/116/202204261021452811.html

Random recommended