Java实战之校园外卖点餐系统的实现
目录
一、项目简述二、效果图展示三、核心代码管理员controller控制层管理员角色controler控制层后台登录控制层订单模块controller控制层一、项目简述
环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
JSP +Spring + SpringMVC + MyBatis + css + JavaScript + JQuery + Ajax + layui+ maven等等。
二、效果图展示
三、核心代码
管理员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){ Listlist = 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 us= userService.list(); int total = (int) new PageInfo<>(us).getTotal();//总条数 page.setTotal(total); model.addAttribute("us", us);//所有用户 model.addAttribute("total",total); Map > user_roles = new HashMap<>(); //每个用户对应的权限 for (User user : us) { List 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 rs = roleService.list(); model.addAttribute("rs", rs); User user =userService.get(id); model.addAttribute("user", user); //当前拥有的角色 List 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());//分页查询 Listrs= roleService.list(); int total = (int) new PageInfo<>(rs).getTotal();//总条数 page.setTotal(total); model.addAttribute("rs", rs); model.addAttribute("roleSize",total); Map > role_permissions = new HashMap<>(); for (Role role : rs) { List 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 ps = permissionService.list(); model.addAttribute("ps", ps); //当前管理员拥有的权限 List 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 @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 = ""; if(us!=null){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //上次时间 Date time = us.getLasttime(); lastLoginTime = sdf.format(time); //新时间 String format = sdf.format(new Date()); //string转date 不处理时间格式会不理想 ParsePosition pos = new ParsePosition(0); Date strtodate = sdf.parse(format, pos); us.setLasttime(strtodate); userService.update(us); } 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"; } } }
订单模块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()); Listos= 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点餐系统的资料请关注脚本之家其它相关文章!
X 关闭
X 关闭
- 15G资费不大降!三大运营商谁提供的5G网速最快?中国信通院给出答案
- 2联想拯救者Y70发布最新预告:售价2970元起 迄今最便宜的骁龙8+旗舰
- 3亚马逊开始大规模推广掌纹支付技术 顾客可使用“挥手付”结账
- 4现代和起亚上半年出口20万辆新能源汽车同比增长30.6%
- 5如何让居民5分钟使用到各种设施?沙特“线性城市”来了
- 6AMD实现连续8个季度的增长 季度营收首次突破60亿美元利润更是翻倍
- 7转转集团发布2022年二季度手机行情报告:二手市场“飘香”
- 8充电宝100Wh等于多少毫安?铁路旅客禁止、限制携带和托运物品目录
- 9好消息!京东与腾讯续签三年战略合作协议 加强技术创新与供应链服务
- 10名创优品拟通过香港IPO全球发售4100万股 全球发售所得款项有什么用处?