Java前后端分离的在线点餐系统实现详解

 更新时间:2022年01月24日 16:14:30   作者:OldWinePot  
这是一个基于SpringBoot+Vue框架开发的在线点餐系统。首先,这是一个前后端分离的项目。具有一个在线点餐系统该有的所有功能,感兴趣的朋友快来看看吧

项目功能:

此项目分为两个角色:普通用户和管理员。普通用户有登录注册、浏览商品信息、添加购物车、结算订单、查看个人信息、查看个人订单详情等等功能。管理员有管理所有商品信息、管理所有订单信息、管理所有用户信息、查看收益数据图表等等功能。

应用技术:

SpringBoot + VueCli + MySQL + MyBatis + Redis + ElementUI

运行环境:

IntelliJ IDEA2019.3.5 + MySQL5.7+ Redis5.0.5 + JDK1.8 + Maven3.6.3+ Node14.16.1

管理员controller:

/**
 * 管理员controller
 */
@Controller
@RequestMapping("/config")
public class UserController {
    @Autowired
    UserRoleService userRoleService;
    @Autowired
    UserService userService;
    @Autowired
    RoleService roleService;
 
 
    @RequestMapping("/enableStatus")
    @ResponseBody
    public String enableStatus(@RequestParam(value = "name") String name){
        return userService.enableStatus(name);
    }
 
    @RequestMapping("/stopStatus")
    @ResponseBody
    public String stopStatus(@RequestParam(value = "name") String name){
        return userService.stopStatus(name);
    }
 
    @RequestMapping("/adminAdd")
    public String adminadd(Model model){
        List<Role> list = roleService.list();
        model.addAttribute("rolelist",list);
        return "syspage/admin-add";
    }
 
    @RequestMapping("/listUser")
    public String list(Model model, Page page){
 
        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){
        userService.delete(id);
        return "redirect:listUser";
    }
 
    @RequestMapping("updateUser")
    public String update(User user, long[] roleIds){
        userRoleService.setRoles(user,roleIds);
         
        String password=user.getPassword();
        //如果在修改的时候没有设置密码,就表示不改动密码
        if(user.getPassword().length()!=0) {
            String salt = new SecureRandomNumberGenerator().nextBytes().toString();
            int times = 2;
            String algorithmName = "md5";
            String encodedPassword = new SimpleHash(algorithmName,password,salt,times).toString();
            user.setSalt(salt);
            user.setPassword(encodedPassword);
        }
        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.setSalt(salt);
        u.setStatus(1);
        u.setAddress(user.getAddress());
        u.setPhone(user.getPhone());
        userService.add(u);
 
        userRoleService.setRoles(u,roleIds);
         
        return "redirect:listUser";
    }
 
}

管理员角色controler:

/**
 * 管理员角色controler
 */
@Controller
@RequestMapping("/config")
public class RoleController {
    @Autowired
    RoleService roleService;
    @Autowired
    RolePermissionService rolePermissionService;
    @Autowired
    PermissionService permissionService;
 
    @RequestMapping("/addRoleUI")
    public String addRole(){
 
        return "syspage/admin-role-add";
    }
 
    @RequestMapping("/listRole")
    public String list(Model model, Page page){
        PageHelper.offsetPage(page.getStart(),page.getCount());//分页查询
        List<Role> rs= roleService.list();
        int total = (int) new PageInfo<>(rs).getTotal();//总条数
        page.setTotal(total);
 
        model.addAttribute("rs", rs);
 
        model.addAttribute("roleSize",total);
 
        Map<Role,List<Permission>> role_permissions = new HashMap<>();
         
        for (Role role : rs) {
            List<Permission> ps = permissionService.list(role);
            role_permissions.put(role, ps);
        }
        model.addAttribute("role_permissions", role_permissions);
 
        return "syspage/admin-role";
    }
 
    @RequestMapping("/editRole")
    public String list(Model model,long id){
        Role role =roleService.get(id);
        model.addAttribute("role", role);
        //所有权限
        List<Permission> ps = permissionService.list();
        model.addAttribute("ps", ps);
        //当前管理员拥有的权限
        List<Permission> currentPermissions = permissionService.list(role);
        model.addAttribute("currentPermissions", currentPermissions);
 
        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";
    }   
 
}

订单模块controller: 

/**
 * 订单模块controller
 */
@Controller
@RequestMapping("/order")
public class OrderController {
 
    @Autowired
    OrderService orderService;
    @Autowired
    OrderItemService orderItemService;
 
    /**
     * 所有订单
     * @param model
     * @param page
     * @return
     */
    @RequestMapping("/list")
    public String list(Model model, Page page){
        PageHelper.offsetPage(page.getStart(),page.getCount());
 
        List<Order> os= orderService.list();
 
        int total = (int) new PageInfo<>(os).getTotal();
        page.setTotal(total);
        //为订单添加订单项数据
        orderItemService.fill(os);
 
        model.addAttribute("os", os);
        model.addAttribute("page", page);
        model.addAttribute("totals", total);
 
        return "ordermodule/order-list";
    }
 
    /**
     * 订单发货
     * @param o
     * @return
     */
    @RequestMapping("/orderDelivery")
    public String delivery(Order o){
        o.setStatus(2);
        orderService.update(o);
        return "redirect:list";
    }
 
    /**
     * 查看当前订单的订单项
     * @param oid
     * @param model
     * @return
     */
    @RequestMapping("/seeOrderItem")
    public String seeOrderItem(int oid,Model model){
        Order o = orderService.get(oid);
        orderItemService.fill(o);
        model.addAttribute("orderItems",o.getOrderItems());
        model.addAttribute("total",o.getOrderItems().size());
        model.addAttribute("totalPrice",o.getTotal());
        return "ordermodule/orderItem-list";
    }
 
}

到此这篇关于Java前后端分离的在线点餐系统实现详解的文章就介绍到这了,更多相关Java 在线点餐系统内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • springboot 日志实现过程

    springboot 日志实现过程

    Spring Boot 使用 SLF4J 作为日志门面,Logback 或 Log4j2 作为日志实现,日志门面提供统一接口,简化日志记录,实现负责具体功能,Spring Boot 默认使用 SLF4J 和 Logback,可以通过配置文件或注解进行日志记录和控制,感兴趣的朋友一起看看吧
    2025-01-01
  • Spring Boot结合ECharts案例演示示例

    Spring Boot结合ECharts案例演示示例

    本文主要主要介绍了Spring Boot结合ECharts案例演示示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2022-06-06
  • Spring mvc整合mybatis(crud+分页插件)操作mysql

    Spring mvc整合mybatis(crud+分页插件)操作mysql

    这篇文章主要介绍了Spring mvc整合mybatis(crud+分页插件)操作mysql的步骤详解,需要的朋友可以参考下
    2017-04-04
  • Spring boot项目中异常拦截设计和处理详解

    Spring boot项目中异常拦截设计和处理详解

    这篇文章主要介给大家绍了关于Spring boot项目中异常拦截设计和处理的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用spring boot具有一定的参考学习价值,需要的朋友们下面随着小编来一起看看吧
    2018-12-12
  • Java mysql特殊形式的查询语句详解

    Java mysql特殊形式的查询语句详解

    这篇文章主要介绍了Java mysql特殊形式的查询,包括子查询和联合查询、自身连接查询问题,本文通过sql语句给大家介绍的非常详细,需要的朋友可以参考下
    2022-02-02
  • mybatis之BaseTypeHandler用法解读

    mybatis之BaseTypeHandler用法解读

    这篇文章主要介绍了mybatis之BaseTypeHandler用法解读,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-04-04
  • java中for和forEach的速度比较实例Demo

    java中for和forEach的速度比较实例Demo

    for循环中的循环条件中的变量只求一次值,而foreach语句是java5新增,在遍历数组、集合的时候,foreach拥有不错的性能,这篇文章主要给大家介绍了关于java中for和forEach速度比较的相关资料,需要的朋友可以参考下
    2021-08-08
  • 关于struts2中Action名字的大小写问题浅谈

    关于struts2中Action名字的大小写问题浅谈

    这篇文章主要给大家介绍了关于struts2中Action名字大小写问题的相关资料,文中介绍的非常详细,对大家具有一定的参考学习价值,需要的朋友们下面跟着小编一起来学习学习吧。
    2017-06-06
  • Java语言中的自定义类加载器实例解析

    Java语言中的自定义类加载器实例解析

    这篇文章主要介绍了Java语言中的自定义类加载器实例解析,分享了相关代码示例,小编觉得还是挺不错的,具有一定借鉴价值,需要的朋友可以参考下
    2018-02-02
  • Java 数据结构与算法系列精讲之队列

    Java 数据结构与算法系列精讲之队列

    这篇文章主要介绍了Java队列数据结构的实现,队列是一种特殊的线性表,只允许在表的队头进行删除操作,在表的后端进行插入操作,队列是一个有序表先进先出,想了解更多相关资料的小伙伴可以参考下面文章的详细内容
    2022-02-02

最新评论