基于javaweb+mysql的springboot点餐系统(java+springboot+ssm+mysql+maven)

基于javaweb+mysql的springboot点餐系统(java+springboot+ssm+mysql+maven)

运行环境

Java≥8、MySQL≥5.7

开发工具

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

适用

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

功能说明

基于javaweb+mysql的SpringBoot点餐系统(java+springboot+ssm+mysql+maven)

一、项目简述

功能:数据库采用mysq昨为数据存储,系统中涉及到的关 键表有,用户表、用户详情表、商品表、订单表、商品订 单关联表、评价表等等。本系统分为前端和后端,前端功 能有:登录注册、修改个人信息、修改收货地址、查看商 品、加购商品、结算商品,对订单进行评价、用户留言等 功能;后端功能有:登录、商品管理、用户管理、订单管 理、留言公告管理等功能。本系统中的购物车功能设计、io流读写图片存放本地、订单导出、“echarts插件实现订单信 息统计、后台批量操作、pagehelper实现分页等细节值得 学习。

二、项目运行

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

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

    }

    /**
     * 创建公告
     */
    @RequestMapping("/admin/createNotice")
    public  String createNotice(String title,String content,int status){
        noticeService.addNotice(title,content,status);
        return "redirect:/admin/toNoticeList";
    }

    /**
     * 修改公告
     */
    @RequestMapping("/admin/updateNotice")
    public  String updateNotice(Integer id,String utitle,String ucontent,int ustatus){
        noticeService.updateNotice(id,utitle,ucontent,ustatus);
        return "redirect:/admin/toNoticeList";
    }

    /**
     * 批量删除公告
     */
    @RequestMapping("/admin/deleteBatchNotice")
    public  String deleteBatchNotice(@RequestParam("id") Integer[] id){
        noticeService.deleteNotices(id);
        return "redirect:/admin/toNoticeList";
    }

    /**
     * 批量显示公告
     */
    @RequestMapping("/admin/showBatchNotice")
    public  String showBatchNotice(@RequestParam("id") Integer[] id){
        noticeService.showNotices(id);
        return "redirect:/admin/toNoticeList";
    }

    /**
     * 批量关闭公告
     */
    @RequestMapping("/admin/closeBatchNotice")
    public  String closeBatchNotice(@RequestParam("id") Integer[] id){
        noticeService.closeNotices(id);
        return "redirect:/admin/toNoticeList";
    }

}
        }
        return ResponseMessageEnum.SUCCESS.getCode();
    }

}

/**

 */

@Controller
public class Back_AdminController {

    @Autowired
    private UserService userService;
    @Autowired
    private RoleService roleService;

    @GetMapping("/admin/toMemberList")
    public String toMemberList(Model model){

        List<User> allUser = userService.findAllUser();
        List<Role> roleList  = roleService.findRoleList();
        model.addAttribute("userList",allUser);
        model.addAttribute("roleList", roleList);
        return "/admin/member/member_list";
    }

		} catch (IOException e) {
		}
		return new BaseState(false, AppInfo.IO_ERROR);
	}

	private static boolean validType(String type, String[] allowTypes) {
		List<String> list = Arrays.asList(allowTypes);

		return list.contains(type);
	}
}

/**

 */

@Controller
public class Back_LeaveController {

    //留言信息处理
    @Autowired
    private LeaveService leaveService;
    @Autowired
    private UserService userService;

    @RequestMapping("/admin/toLeaveList")
        model.addAttribute("page", pageInfo);
        return "/admin/product/product_list";
    }

    /**
     * 去添加商品页面
     */
    @RequestMapping("/admin/toAddProductView")
    public String toAddProductView() {
        return "/admin/product/product_edit";
    }
    /**
     * 新增商品
     */
    @RequestMapping("/admin/addNewProduct")
    public String addNewProduct(MultipartFile imageUrl, HttpServletRequest request,Product product, BindingResult bindingResult){
        //1-依次 得到图片的后缀名、得到菜品的种类、生成新的图片名
        String suffix = imageUrl.getOriginalFilename().substring(imageUrl.getOriginalFilename().lastIndexOf("."));
       // int kindId = product.getProductKindId();
        String newPicName = UUIDUtils.getUUID15()+suffix;
        //2-获取项目路径  指定图片按照商品的分类存放 id为1的图片 放置/static/pro/upload/下的1文件夹里
        ServletContext sc = request.getSession().getServletContext();
        String localPath = "/static/pro/upload/";
        //String localPath = "/static/pro/upload/"+kindId+"/";
        String path = sc.getRealPath(localPath);
        //2-2-如果图片不为空 以流的形式存放到指定的文件夹中
        FileOutputStream fos = null;
        InputStream in = null;
        if (!imageUrl.isEmpty()){
            try{
                fos = new FileOutputStream(path + newPicName);
                in = imageUrl.getInputStream();
                int b = 0;
                while((b = in.read()) != -1){
                    fos.write(b);
                }
                //2-3关闭流
                fos.close();
                in.close();
            }catch (Exception e){
                e.printStackTrace();
            }
        });
        model.addAttribute("product",product);
        model.addAttribute("HotProductList",hotProductList);
        //3-跳转到商品详情页面
        return "/pages/list/detail";
    }
}

/**

 */
public class ObjectExcelViewOrder extends AbstractExcelView {

    private String fileName;
    private String excelTitle;
    public ObjectExcelViewOrder(String fileName, String excelTitle){
        this.fileName = fileName;
        this.excelTitle = excelTitle;
    }
    @SuppressWarnings("deprecation")
    @Override
    protected void buildExcelDocument(Map<String, Object> model,
                                      HSSFWorkbook workbook, HttpServletRequest request,
                                      HttpServletResponse response) throws Exception {
        //Date date = new Date();
        //String filename = Tools.date2Str(date, "yyyyMMddHHmmss");
        HSSFSheet sheet =sheet = workbook.createSheet("sheet1");

    /**
     * 不指定名字的话,自动创建一个方法名第一个字母小写的bean
     * *@Bean(name = "securityManager")
     * @return
     */
    @Bean
    public SecurityManager securityManager(AuthRealm m) {
        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
        // 设置realm.
        securityManager.setRealm(m);
        return securityManager;
    }

    /**
     * 生命周期处理器--shiro
     * @return
     */
    @Bean
    public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
        return new LifecycleBeanPostProcessor();
    }

    /**
     * 开启Shiro的注解(如@RequiresRoles, @RequiresPermissions),需借助SpringAOP扫描使用Shiro注解的类,并在必要时进行安全逻辑验证
     * 配置以下两个bean(DefaultAdvisorAutoProxyCreator(可选)和AuthorizationAttributeSourceAdvisor)即可实现此功能
     * @return
     * @return
     */
    @Bean
    @DependsOn({"lifecycleBeanPostProcessor"})
    public DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator() {
        DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
        advisorAutoProxyCreator.setProxyTargetClass(true);
        return advisorAutoProxyCreator;
    }

    @Bean
    public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) {
        AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
        authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
        return authorizationAttributeSourceAdvisor;
    }

}
		
		if ( this.configManager == null || !this.configManager.valid() ) {
			return new BaseState( false, AppInfo.CONFIG_ERROR ).toJSONString();
		}
		
		State state = null;
		
		int actionCode = ActionMap.getType( this.actionType );
		
		Map<String, Object> conf = null;
		
		switch ( actionCode ) {
		
			case ActionMap.CONFIG:
				return this.configManager.getAllConfig().toString();
				
			case ActionMap.UPLOAD_IMAGE:
			case ActionMap.UPLOAD_SCRAWL:
			case ActionMap.UPLOAD_VIDEO:
			case ActionMap.UPLOAD_FILE:
				conf = this.configManager.getConfig( actionCode );
				state = new Uploader( request, conf ).doExec();
				break;
				
			case ActionMap.CATCH_IMAGE:
				conf = configManager.getConfig( actionCode );
				String[] list = this.request.getParameterValues( (String)conf.get( "fieldName" ) );
				state = new ImageHunter( conf ).capture( list );
				break;
				
			case ActionMap.LIST_IMAGE:
			case ActionMap.LIST_FILE:
				conf = configManager.getConfig( actionCode );
				int start = this.getStartIndex();
				state = new FileManager( conf ).listFile( start );
				break;
				
		}
		
		return state.toJSONString();
		
	}
	
	public int getStartIndex () {
		
		String start = this.request.getParameter( "start" );
		
		try {
			return Integer.parseInt( start );
		} catch ( Exception e ) {
			return 0;
		}
		
        String pRoleName = "";
        String sRoleName = "";
        int pCount = 0;
        int sCount = 0;
        for(User user : userList){
        /*    if("超级管理员".equals(user.getRole().getRoleName())){
                sRoleName = sRoleName + " " + user.getUsername();
                sCount = sCount + 1;
            }else{
                pRoleName = pRoleName + "  " + user.getUsername();
                pCount = pCount + 1;
            }*/
        }

        model.addAttribute("pRoleName", pRoleName);
        model.addAttribute("pCount", pCount);
        model.addAttribute("sRoleName" , sRoleName);
        model.addAttribute("sCount", sCount);
        return "/admin/member/admin_competence";
    }

}

/**

 */
        response.setContentType("text/html;charset=utf-8");
        //1-生成订单编号
        String orderId = UUID.randomUUID().toString();
        User user = (User) session.getAttribute("user");
        Map<Product, Integer> myCartMap = (Map<Product, Integer>) session.getAttribute("myCartMap");
        //1-保存订单信息
        orderService.saveOrder(user,ids, myCartMap, orderId);
        //--------------------------------------支付操作未实现--------------------------
        //2-支付成功后修改订单状态
        orderService.updateOrderStatus(0, orderId);
        //3-清空购物车
        List<Product> list = productService.findProductsById(ids);
        for (Product product:list) {
            myCartMap.remove(product);
        }
        System.out.println("size:"+myCartMap.size());

        return "pages/order/confirm";
    }
}

/**
      登录相关的controller
 */

@Controller
public class LoginController {

    @Autowired
        return "/pages/index";
    }
}

/**
  公告相关controller
 */
@Controller
public class Back_NoticeController {
    @Autowired
    private NoticeService noticeService;

    /**
     * 展示公告列表
     * @return
     */
    @RequestMapping("/admin/toNoticeList")
    public String sortAds(@RequestParam(required = true, defaultValue = "1") Integer page,Model model) {
        PageHelper.startPage(page, 10);
        List<Notice> noticeList = noticeService.findAll();
        model.addAttribute("noticeList",noticeList);
        PageInfo<Notice> p = new PageInfo<>(noticeList);
        model.addAttribute("page", p);
        return "/admin/notice/notice_list";
    }

    /**
     * 创建公告
     */
    @RequestMapping("/admin/createNotice")
     */
    @RequestMapping("/updateTel")
    public String updateTel(){
        return "/pages/user/user_telephone";
    }

    /*
     * 更换手机号
     * @param newTel
     * @return
     */
    @RequestMapping("/saveTelephone")
    public String saveTel(String newTel,Model model,HttpSession session){
      /*  String regexMobile = "^((17[0-9])|(14[0-9])|(13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
        User user = (User) session.getAttribute("user");
        if(user == null){
            return "/login";
        }

        if(!newTel.matches(regexMobile)){
            model.addAttribute("msg","格式不对!");
            return "/pages/user/user_telephone";
        }
        userService.updateTel(newTel,user.getUserId());
        model.addAttribute("msg","修改成功");*/
        return "redirect:/userAccount";
    }

    /**
     * 解绑手机号
     * @return
     */
    @RequestMapping("/deleteTel")
    public String deleteTel(HttpSession session){
       /* User user = (User) session.getAttribute("user");
        userService.deleteTel(user.getUserId());*/
        return "redirect:/userAccount";
    }

    /**

        if ( isAjaxUpload ) {
            upload.setHeaderEncoding( "UTF-8" );
        }

		try {
			FileItemIterator iterator = upload.getItemIterator(request);

			while (iterator.hasNext()) {
				fileStream = iterator.next();

				if (!fileStream.isFormField())
					break;
				fileStream = null;
			}

			if (fileStream == null) {
				return new BaseState(false, AppInfo.NOTFOUND_UPLOAD_DATA);
			}

			String savePath = (String) conf.get("savePath");
			String originFileName = fileStream.getName();
			String suffix = FileType.getSuffixByFilename(originFileName);

			originFileName = originFileName.substring(0,
					originFileName.length() - suffix.length());
			savePath = savePath + suffix;

			long maxSize = ((Long) conf.get("maxSize")).longValue();

			if (!validType(suffix, (String[]) conf.get("allowFiles"))) {
				return new BaseState(false, AppInfo.NOT_ALLOW_FILE_TYPE);
			}

			savePath = PathFormat.parse(savePath, originFileName);

			String physicalPath = (String) conf.get("rootPath") + savePath;

			InputStream is = fileStream.openStream();
			State storageState = StorageManager.saveFileByInputStream(is,
        //1-根据商品id查询商品信息
        Product product = productService.findProductById(id);
        //2-查询热门商品信息列表
        List<Product> hotProductList = new ArrayList<>();
            //2-1-从热门商品表中取出两个
        productService.findProductBannerByCount(2).forEach(productBanner -> {
            Product dbProduct = productService.findProductById(productBanner.getProductId());
            if(dbProduct != null){
                hotProductList.add(dbProduct);
            }
        });
        model.addAttribute("product",product);
        model.addAttribute("HotProductList",hotProductList);
        //3-跳转到商品详情页面
        return "/pages/list/detail";
    }
}

/**

 */
public class ObjectExcelViewOrder extends AbstractExcelView {

    private String fileName;
    private String excelTitle;
    public ObjectExcelViewOrder(String fileName, String excelTitle){
        this.fileName = fileName;
        Integer userId = ((User) session.getAttribute("user")).getId();
        User user = userService.findUserInfo(userId);
        model.addAttribute("user", user);
        return "/admin/member/personal_info";
    }

    @PostMapping("/admin/updateAdmin")
    public String updateUser(User user) {
        userService.updateUser(user);
        return "redirect:/personal_info";
    }

    @GetMapping("/admin/updateAdminById")
    public String updateUserById(User user) {
        userService.updateUserById(user);
        return "redirect:/personal_info";
    }
/*
    @RequestMapping("/admin/check")
    @ResponseBody
    public String checkPassowrd(User user, String npassword){

*//*        String password = userService.findUserByUserId(user.getUserId()).getPassword();

        if(user.getPassword().equals(password)){

            user.setPassword(npassword);
            userService.updateUserPassword(user);

            return "true";
        }else{
            return "false";
        }*//*

        return "false";
    }*/

    @RequestMapping("/addAdmin")
    public String addAdmin(User user) {

        userService.addUser(user);

        return "redirect:/admin/toMemberList";
    }

    @RequestMapping("/deleteAdmins")
    public String deleteAdmins(@RequestParam("userId") String[] userIds){
        userService.deleteAdminsById(userIds);
        return "redirect:/admin/toMemberList";
    }
        HSSFCell titleCell = getCell(sheet, 0, 0);
        setText(titleCell,excelTitle);
        HSSFCellStyle titleStyle = workbook.createCellStyle();
        titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中
        titleStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        HSSFFont titleFont=workbook.createFont();
        titleFont.setFontHeightInPoints((short)14);//字体大小
        titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//字体加粗
        titleStyle.setFont(titleFont);
        titleCell.setCellStyle(titleStyle);
        //设置excel表头数据
        HSSFCellStyle headerStyle = workbook.createCellStyle(); //标题样式
        headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        headerStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        HSSFFont headerFont = workbook.createFont();	//标题字体
        headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        headerFont.setFontHeightInPoints((short)11);
        headerStyle.setFont(headerFont);
        short width = 20,height=25*20;
        sheet.setDefaultColumnWidth(width);
        for(int i=0; i<len; i++){ //设置标题
            String title = titles.get(i);
            cell = getCell(sheet, 1, i);
            cell.setCellStyle(headerStyle);
            setText(cell,title);
        }

        sheet.getRow(0).setHeight(height);
        //设置具体每行文本数据
        HSSFCellStyle contentStyle = workbook.createCellStyle(); //内容样式
        contentStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);//水平居中
        contentStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);//垂直居中
        //设置具体每行数值数据
        HSSFCellStyle valueStyle = workbook.createCellStyle(); //内容样式
        valueStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);//水平居中
        valueStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);//垂直居中
        HSSFDataFormat df = workbook.createDataFormat();//此处设置数据格式  
        valueStyle.setDataFormat(df.getFormat("#,#0.0")); //小数点后保留两位,可以写contentStyle.setDataFormat(df.getFormat("#,#0.00"));  

        List<List<Object>> varList = (List<List<Object>>) model.get("varList");
        System.out.println("Shiro拦截器工厂类注入成功");
        return shiroFilterFactoryBean;
    }

    @Bean
    public EhCacheManager ehCacheManager() {
        EhCacheManager cacheManager = new EhCacheManager();
        return cacheManager;
    }

    /**
     * 不指定名字的话,自动创建一个方法名第一个字母小写的bean
     * *@Bean(name = "securityManager")
     * @return
     */
    @Bean
    public SecurityManager securityManager(AuthRealm m) {
        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
        // 设置realm.
        securityManager.setRealm(m);
        return securityManager;
    }

    /**
     * 生命周期处理器--shiro
     * @return
     */
    @Bean
    public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
        return new LifecycleBeanPostProcessor();
    }

    /**
     * 开启Shiro的注解(如@RequiresRoles, @RequiresPermissions),需借助SpringAOP扫描使用Shiro注解的类,并在必要时进行安全逻辑验证
     * 配置以下两个bean(DefaultAdvisorAutoProxyCreator(可选)和AuthorizationAttributeSourceAdvisor)即可实现此功能
     * @return
     * @return
     */
    @Bean
    @DependsOn({"lifecycleBeanPostProcessor"})
    public DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator() {
        DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
        advisorAutoProxyCreator.setProxyTargetClass(true);
        return advisorAutoProxyCreator;
    }

    @Bean
            colIndex = ObjectExcelUtil.setSingleCellText(sheet,cell,rowIndex,colIndex,ObjectExcelUtil.showNullData(data.getId()),contentStyle);
            //2-订单编号
            colIndex = ObjectExcelUtil.setSingleCellText(sheet,cell,rowIndex,colIndex,ObjectExcelUtil.showNullData(data.getOrderId()),contentStyle);
            //3-订单金额
            colIndex = ObjectExcelUtil.setSingleCellText(sheet,cell,rowIndex,colIndex,ObjectExcelUtil.showNullData(data.getMoney()),contentStyle);
            //4-收货人
            colIndex = ObjectExcelUtil.setSingleCellText(sheet,cell,rowIndex,colIndex,ObjectExcelUtil.showNullData(data.getUserId()),contentStyle);
            //5-收获地址
            colIndex = ObjectExcelUtil.setSingleCellText(sheet,cell,rowIndex,colIndex,ObjectExcelUtil.showNullData(data.getAddressInfo()),contentStyle);
            //6-下单时间
            colIndex = ObjectExcelUtil.setSingleCellText(sheet,cell,rowIndex,colIndex,ObjectExcelUtil.showNullData(data.getOrderDate()),contentStyle);
            //7-订单状态
            colIndex = ObjectExcelUtil.setSingleCellText(sheet,cell,rowIndex,colIndex,ObjectExcelUtil.showNullData(data.getStatus()),contentStyle);
            rowIndex ++;
        }
    }
}

/**

 */

@Controller
public class OrderController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private UserService userService;
    @Autowired
        //设置具体每行数值数据
        HSSFCellStyle valueStyle = workbook.createCellStyle(); //内容样式
        valueStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);//水平居中
        valueStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);//垂直居中
        HSSFDataFormat df = workbook.createDataFormat();//此处设置数据格式  
        valueStyle.setDataFormat(df.getFormat("#,#0.0")); //小数点后保留两位,可以写contentStyle.setDataFormat(df.getFormat("#,#0.00"));  

        List<List<Object>> varList = (List<List<Object>>) model.get("varList");
        int varCount = varList.size();
        int rowIndex = 2;//第三行
        for(int i=0; i<varCount; i++){
            //初始参数
            OrderExcelExportVO data = (OrderExcelExportVO)varList.get(i);
            int colIndex = 0;//第一列
            //1-订单序号
            colIndex = ObjectExcelUtil.setSingleCellText(sheet,cell,rowIndex,colIndex,ObjectExcelUtil.showNullData(data.getId()),contentStyle);
            //2-订单编号
            colIndex = ObjectExcelUtil.setSingleCellText(sheet,cell,rowIndex,colIndex,ObjectExcelUtil.showNullData(data.getOrderId()),contentStyle);
            //3-订单金额
            colIndex = ObjectExcelUtil.setSingleCellText(sheet,cell,rowIndex,colIndex,ObjectExcelUtil.showNullData(data.getMoney()),contentStyle);
            //4-收货人
            colIndex = ObjectExcelUtil.setSingleCellText(sheet,cell,rowIndex,colIndex,ObjectExcelUtil.showNullData(data.getUserId()),contentStyle);
            //5-收获地址
            colIndex = ObjectExcelUtil.setSingleCellText(sheet,cell,rowIndex,colIndex,ObjectExcelUtil.showNullData(data.getAddressInfo()),contentStyle);
            //6-下单时间
            colIndex = ObjectExcelUtil.setSingleCellText(sheet,cell,rowIndex,colIndex,ObjectExcelUtil.showNullData(data.getOrderDate()),contentStyle);
            //7-订单状态
            colIndex = ObjectExcelUtil.setSingleCellText(sheet,cell,rowIndex,colIndex,ObjectExcelUtil.showNullData(data.getStatus()),contentStyle);
            rowIndex ++;
        }
    }
}

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值