您好,登錄后才能下訂單哦!
這篇文章跟大家分析一下“如何進行Java前后端分離的在線點餐系統實現”。內容詳細易懂,對“如何進行Java前后端分離的在線點餐系統實現”感興趣的朋友可以跟著小編的思路慢慢深入來閱讀一下,希望閱讀后能夠對大家有所幫助。下面跟著小編一起深入學習“如何進行Java前后端分離的在線點餐系統實現”的知識吧。
此項目分為兩個角色:普通用戶和管理員。普通用戶有登錄注冊、瀏覽商品信息、添加購物車、結算訂單、查看個人信息、查看個人訂單詳情等等功能。管理員有管理所有商品信息、管理所有訂單信息、管理所有用戶信息、查看收益數據圖表等等功能。
應用技術: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 @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 */ @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 @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前后端分離的在線點餐系統實現就分享到這里啦,希望上述內容能夠讓大家有所提升。如果想要學習更多知識,請大家多多留意小編的更新。謝謝大家關注一下億速云網站!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。