基于javaweb+mysql的ssm+maven校园外卖点餐系统(java+ssm+jsp+maven+mysql)

基于javaweb+mysql的ssm+maven校园外卖点餐系统(java+ssm+jsp+maven+mysql)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

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

适用

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

功能说明

基于javaweb+mysql的SSM+Maven校园外卖点餐系统(java+ssm+jsp+maven+mysql)

一、项目简述 环境配置:

Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)

项目技术:

JSP +Spring + SpringMVC + MyBatis + css + JavaScript + JQuery + Ajax + layui+ maven等等。

        return "redirect:listRole";
    }
 
    @RequestMapping("/addRole")
    public String list(Model model, Role role){
        roleService.add(role);
        return "redirect:listRole";
    }

    @RequestMapping("/deleteRole")
    public String delete(Model model, long id){
        roleService.delete(id);
        return "redirect:listRole";
    }   
 
}
package com.demo.controller;

/**
 * 后台登陆
 */
@Controller
@RequestMapping("")
public class LoginController {

    @Autowired
    UserService userService;

    @RequestMapping(value="/login",method= RequestMethod.POST)
    public String login(Model model, String name, String password){//throws ParseException
        Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken(name,password);
        try {
            subject.login(token);
            User us = userService.getByName(name);
            String lastLoginTime = "";
		}

	}
	
	public String invoke() {
		
		if ( actionType == null || !ActionMap.mapping.containsKey( actionType ) ) {
			return new BaseState( false, AppInfo.INVALID_ACTION ).toJSONString();
		}
		
		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();
        model.addAttribute("reviews",list);
        model.addAttribute("rs",list.size());

        return "forepage/proDetail";
    }

    /**
     * 注册页面
     * @return
     */
    @RequestMapping("/foreRegisterUI")
    public String registerUI(){
        return "forepage/foreRegister";
    }

    /**
     * 登陆页面
     * @return
     */
    @RequestMapping("/foreLoginUI")
    public String foreLoginUI(){
        return "forepage/forelogin";
    }

    /**
     * 模态窗口登陆 验证
     * @param customer
     * @param session
     * @return
     */
    @RequestMapping("/foreMtLogin")
    @ResponseBody
    public String foreIsLogin(Customer customer, HttpSession session){
        Customer cst = customerService.foreLogin(customer);
        if(null==cst){
            return "false";
        }
        session.setAttribute("cst", cst);
        return "true";
    }

    /**
			
		} else {
			return this.invoke();
		}

	}
	
	public String invoke() {
		
		if ( actionType == null || !ActionMap.mapping.containsKey( actionType ) ) {
			return new BaseState( false, AppInfo.INVALID_ACTION ).toJSONString();
		}
		
		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:
            }
            if (us.getStatus()==1){
                Session session=subject.getSession();
                session.setAttribute("subject", subject);
                session.setAttribute("lastLoginTime",lastLoginTime);
                return "redirect:index";
            }else {
                model.addAttribute("error", "账号已被停用!");
                return "/login";
            }

        } catch (AuthenticationException e) {
            model.addAttribute("error", "验证失败!");
            return "/login";
        }
    }

}
package com.demo.controller;

/**
 * 权限模块controller
 */
@Controller
@RequestMapping("/config")
public class PermissionController {
    @Autowired
    PermissionService permissionService;

    /**
     * 添加权限页面
     * @return
     */
    @RequestMapping("/adminPerAddUI")
    public String addUI(){
        return "syspage/admin-permission-add";
         *   不需要登录也可以访问的已经确定了,但是需要登录才能够访问,截止目前为止还不能确定,所以这个过滤器就判断如果不是注册,登录,产品这些,就进行登录校验
         * 1. 准备字符串数组 noNeedAuthPage,存放哪些不需要登录也能访问的路径
         * 2. 获取uri
         * 3. 去掉前缀/fore
         * 4. 如果访问的地址是/fore开头
         * 4.1 取出fore后面的字符串,比如是forecart,那么就取出cart
         * 4.2 判断cart是否是在noNeedAuthPage
         * 4.2 如果不在,那么就需要进行是否登录验证
         * 4.3 从session中取出"cst"对象
         * 4.4 如果对象不存在,就客户端跳转到login.jsp
         * 4.5 否则就正常执行
         */
        HttpSession session = request.getSession();
        String contextPath=session.getServletContext().getContextPath()+"/fore";
        //准备字符串数组 noNeedAuthPage,存放哪些不需要登录也能访问的路径
        String[] noNeedAuthPage = new String[]{
                "Index", //首页
                "DetailUI", //商品详情页
                "RegisterUI",  //注册页
                "Register",  //注册
                "LoginUI",  //登陆页
                "Login",     //登陆
                "IsLogin",  //判断是否登陆
                "MtLogin", //模态登陆验证
                "CstLoginOut", //退出
                "DelOrderItem",//删除购物车项
                "CreateOrder", //提交订单
                "Payed", //支付成功
                "NameLike", //模糊搜索商品
                "FindCategory", //查看分类下的商品
                "Zixunadd", //添加资讯
                "LoginMsg", //登陆返回信息
        };
        //获取uri
        String uri = request.getRequestURI(); //访问首页 /fore/foreIndex
        //去掉前缀/fore
        uri = uri.substring(5,uri.length());  //去掉前缀后 /foreIndex
        //如果访问的地址是/fore开头
        if(uri.startsWith("/fore")){
            //判断是否是在noNeedAuthPage
            String method = StringUtils.substringAfterLast(uri,"/fore" ); // 取出/fore后的字符串:Index
            //如果不在,那么就需要进行是否登录验证
            if(!Arrays.asList(noNeedAuthPage).contains(method)){
                Customer customer =(Customer) session.getAttribute("cst");
                if(null==customer){
                    response.sendRedirect("foreLoginUI");
                    return false;
                }
            }
        }

        return true;

    }
        return "syspage/admin-role-edit";
    }

    @RequestMapping("/updateRole")
    public String update(Role role,long[] permissionIds){
        rolePermissionService.setPermissions(role, permissionIds);
        roleService.update(role);
        return "redirect:listRole";
    }
 
    @RequestMapping("/addRole")
    public String list(Model model, Role role){
        roleService.add(role);
        return "redirect:listRole";
    }

    @RequestMapping("/deleteRole")
    public String delete(Model model, long id){
        roleService.delete(id);
        return "redirect:listRole";
    }   
 
}
package com.demo.controller;

/**
 * 后台登陆
 */
@Controller
@RequestMapping("")
public class LoginController {

    @Autowired
    UserService userService;

    @RequestMapping(value="/login",method= RequestMethod.POST)
        PageHelper.offsetPage(page.getStart(),page.getCount());//分页查询
        List<User> us= userService.list();
        int total = (int) new PageInfo<>(us).getTotal();//总条数
        page.setTotal(total);

        model.addAttribute("us", us);//所有用户
        model.addAttribute("total",total);

        Map<User,List<Role>> user_roles = new HashMap<>();
        //每个用户对应的权限
        for (User user : us) {
            List<Role> roles=roleService.listRoles(user);
            user_roles.put(user, roles);
        }
        model.addAttribute("user_roles", user_roles);
 
        return "syspage/admin-list";
    }

    /**
     * 修改管理员角色
     * @param model
     * @param id
     * @return
     */
    @RequestMapping("/editUser")
    public String edit(Model model, Long id){
        List<Role> rs = roleService.list();
        model.addAttribute("rs", rs);      
        User user =userService.get(id);
        model.addAttribute("user", user);
        //当前拥有的角色
        List<Role> roles =roleService.listRoles(user);
        model.addAttribute("currentRoles", roles);
         
        return "syspage/admin-edit";
    }

    @RequestMapping("deleteUser")
    public String delete(Model model, long id){
@Controller
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;
    @Autowired
    private UserService userService;
    @Autowired
    private CategoryService categoryService;

    @RequestMapping("/list")
    public String list(Model model, Page page){
        PageHelper.offsetPage(page.getStart(),page.getCount());//分页查询
        List<Product> list= productService.list();
        int total = (int) new PageInfo<>(list).getTotal();//总条数
        page.setTotal(total);

        model.addAttribute("list",list);
        model.addAttribute("total",total);
        model.addAttribute("page", page);

        return "productmodule/product-list";
    }

    @RequestMapping("/enableStatus")
    @ResponseBody
    public String enableStatus(@RequestParam(value = "name") String name){
        return productService.enableStatus(name);
    }

    @RequestMapping("/stopStatus")
    @ResponseBody
    public String stopStatus(@RequestParam(value = "name") String name){
        return productService.stopStatus(name);
    }

    @RequestMapping("/productAddUI")
    public String addUI(Model model){

        List<Category> categoryList = categoryService.list();

        List<User> userList = userService.list();
            user.setSalt(salt);
            user.setPassword(encodedPassword);
            user.setPassword(password);
        }
        else
            user.setPassword(null);
         
        userService.update(user);
 
        return "redirect:listUser";
 
    }
 
    @RequestMapping("addUser")
    public String add(User user,long[] roleIds){

        String salt = new SecureRandomNumberGenerator().nextBytes().toString();//生成随机数
        int times = 2;
        String algorithmName = "md5";
          
        String encodedPassword = new SimpleHash(algorithmName,user.getPassword(),salt,times).toString();

        User u = new User();
        u.setName(user.getName());
        u.setPassword(encodedPassword);
        u.setPassword(user.getPassword());
        u.setSalt(salt);
        u.setStatus(1);
        u.setAddress(user.getAddress());
        u.setPhone(user.getPhone());
        userService.add(u);

        userRoleService.setRoles(u,roleIds);
         
        return "redirect:listUser";
    }
 
}
package com.baidu.ueditor;

    public String edit(@RequestParam(value = "id")int id, Model model){
        Category category = categoryService.get(id);
        model.addAttribute("category",category);
        return "productmodule/category-edit";
    }

    @RequestMapping("/updateCategory")
    public String update(Category category, Model model){
        categoryService.update(category);
        return "redirect:list";
    }

}
package com.demo.controller;

/**
 * 用户模块controller
 */
@Controller
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @RequestMapping("/list")
    public String list(Model model, Page page){
        PageHelper.offsetPage(page.getStart(),page.getCount());//分页查询
        List<Customer> list= customerService.list();
        int total = (int) new PageInfo<Customer>(list).getTotal();//总条数
        page.setTotal(total);

        model.addAttribute("list",list);
        model.addAttribute("totals",total);
        return "cstpage/cst-list";
    }
        Customer c = (Customer) session.getAttribute("cst");
        ZiXun z = new ZiXun();
        z.setCstid(c.getId());
        z.setContent(content);
        z.setFabudate(new Date());
        z.setStatus(0);
        ziXunService.save(z);
        return "success";
    }

}
package com.demo.controller;

/**
 * 商品模块controller
 */
@Controller
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;
    @Autowired
    private UserService userService;
    @Autowired
    private CategoryService categoryService;

    @RequestMapping("/list")
    public String list(Model model, Page page){
        PageHelper.offsetPage(page.getStart(),page.getCount());//分页查询

    /**
     * ajax判断客户是否登陆
     * @param session
     * @return
     */
    @RequestMapping("/foreIsLogin")
    @ResponseBody
    public String isLogin(HttpSession session){
        Customer cst = (Customer) session.getAttribute("cst");
        return cst==null?"false":"true";
    }

    /**
     * 注册
     * @param customer
     * @return
     */
    @RequestMapping("/foreRegister")
    public String register(Customer customer){
        customer.setStatus(0);
        customerService.save(customer);
        return "forepage/registerSuccess";
    }

    /**
     * 客户登陆
     * @param customer
     * @param session
     * @return
     */
    @RequestMapping("/foreLogin")
    public String foreLogin(Customer customer, HttpSession session, Model model){
        Customer cst = customerService.foreLogin(customer);
        if (cst!=null){
            session.setAttribute("cst",cst);
            return "redirect:foreIndex";
        }else {
            return "redirect:foreLoginMsg";
        }
    }

    /**
     * 用户登陆返回信息
     * @return
    }

    /**
     * 注册页面
     * @return
     */
    @RequestMapping("/foreRegisterUI")
    public String registerUI(){
        return "forepage/foreRegister";
    }

    /**
     * 登陆页面
     * @return
     */
    @RequestMapping("/foreLoginUI")
    public String foreLoginUI(){
        return "forepage/forelogin";
    }

    /**
     * 模态窗口登陆 验证
     * @param customer
     * @param session
     * @return
     */
    @RequestMapping("/foreMtLogin")
    @ResponseBody
    public String foreIsLogin(Customer customer, HttpSession session){
        Customer cst = customerService.foreLogin(customer);
        if(null==cst){
            return "false";
        }
        session.setAttribute("cst", cst);
        return "true";
    }

    /**
     * ajax判断客户是否登陆
     * @param session
     * @return
     */
    @RequestMapping("/foreIsLogin")
                orderItemService.update(oi);
                found = true;
                break;
            }
        }
        //如果不存在对应的OrderItem,那么就新增一个订单项OrderItem
        if(!found){
            OrderItem oi = new OrderItem();
            oi.setCstid(customer.getId());
            oi.setNumber(number);
            oi.setPid(pid);
            orderItemService.save(oi);
        }

        return "success";
    }

    /**
     * 查看购物车购物车
     * @param model
     * @param session
     * @return
     */
    @RequestMapping("/forecart")
    public String cart(Model model, HttpSession session) {
        Customer customer =(Customer)  session.getAttribute("cst");
        //cstid等于当前登陆用户id 并且oid为null的订单项
        List<OrderItem> ois = orderItemService.listByCustomer(customer.getId());
        //购物车没有商品
        if(ois==null || ois.size()==0){
            return "forepage/cart_noPro";
        }
        int totalProductNumber = 0;
        for (OrderItem oi:ois){
            totalProductNumber += oi.getNumber();
        }
        model.addAttribute("ois", ois);
        model.addAttribute("size", totalProductNumber);

        return "forepage/foreCart";
    }

    /**
     * 删除订单项
     * @param oiid 订单项id
     * @param session
     * @return
     */
    @RequestMapping("/foreDelOrderItem")
        }
        //如果不存在对应的OrderItem,那么就新增一个订单项OrderItem
        if(!found){
            OrderItem oi = new OrderItem();
            oi.setCstid(customer.getId());
            oi.setNumber(number);
            oi.setPid(pid);
            orderItemService.save(oi);
        }

        return "success";
    }

    /**
     * 查看购物车购物车
     * @param model
     * @param session
     * @return
     */
    @RequestMapping("/forecart")
    public String cart(Model model, HttpSession session) {
        Customer customer =(Customer)  session.getAttribute("cst");
        //cstid等于当前登陆用户id 并且oid为null的订单项
        List<OrderItem> ois = orderItemService.listByCustomer(customer.getId());
        //购物车没有商品
        if(ois==null || ois.size()==0){
            return "forepage/cart_noPro";
        }
        int totalProductNumber = 0;
        for (OrderItem oi:ois){
            totalProductNumber += oi.getNumber();
        }
        model.addAttribute("ois", ois);
        model.addAttribute("size", totalProductNumber);

        return "forepage/foreCart";
    }

    /**
     * 删除订单项
     * @param oiid 订单项id
            return "forepage/cart_noPro";
        }
        int totalProductNumber = 0;
        for (OrderItem oi:ois){
            totalProductNumber += oi.getNumber();
        }
        model.addAttribute("ois", ois);
        model.addAttribute("size", totalProductNumber);

        return "forepage/foreCart";
    }

    /**
     * 删除订单项
     * @param oiid 订单项id
     * @param session
     * @return
     */
    @RequestMapping("/foreDelOrderItem")
    @ResponseBody
    public String foreDelOrderItem(int oiid, HttpSession session){
        Customer customer = (Customer) session.getAttribute("cst");
        if(customer==null){
            return "noSuccess";
        }
        orderItemService.del(oiid);
        return "success";
    }

    /*
      点击提交订单
    1. 从session中获取cst对象
    2. 通过参数Order接受收货人
    3. 根据当前时间加上一个4位随机数生成订单号
    4. 根据上述参数,创建订单对象
    5. 把订单状态设置为未支付
    6. 从session中获取订单项集合 ( 在结算功能的ForeController.buy() 13行,订单项集合被放到了session中 )
    7. 把订单加入到数据库,并且遍历订单项集合,设置每个订单项的order,更新到数据库
    8. 统计本次订单的总金额
    9. 客户端跳转到确认支付页forePayed,并带上订单id和总金额
     */
    @RequestMapping("/foreCreateOrder")
    public String createOrder(Model model, String address, HttpSession session){
        /*
          提交订单后,设置code,客户id,支付状态,地址
         */
        Order order = new Order();
        Customer customer =(Customer)  session.getAttribute("cst");
        String orderCode = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) + RandomUtils.nextInt(10000);
        order.setCode(orderCode);

请添加图片描述

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值