赞
踩
作者主页:夜未央5788
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
SpringBoot在线订餐系统项目。主要功能说明: 分为两个角色,餐厅老板、普通用户
餐厅老板可以登录,注册,可以在后台设置菜品目录,菜品详情,查看订单,用户管理,个人中心等
用户查看首页菜品信息,登录后可以点餐,形成购物车,支付后会出现订单详情
本系统采用的技术栈有:springboot、spring、springmvc、mybatis、shiro、jsp、javascript、layui。数据库采用mysql作为数据存储,系统中涉及到的关键表有,用户表、用户详情表、商品表、订单表、商品订单关联表、评价表等等。
本系统分为前台和后台,
前台功能有:
登录注册、修改个人信息、修改收货地址、查看商品、加购商品、结算商品,对订单进行评价、用户留言等功能;
后台功能有:
登录、商品管理、用户管理、订单管理、留言公告管理等功能。本系统中的购物车功能设计、io读写图片存放本地、订单导出、echarts插件实现订单信息统计、后台批量操作、pagehelper实现分页等细节值得学习。
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
6.数据库:MySql 5.7版本;
1. 后端:SpringBoot+MyBatis
2. 前端:Jsp+bootstrap+jQuery
1. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,下载所需要的jar包;
2. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
3. 将项目中application.properties配置文件中的数据库配置改为自己的配置,主要用户名、密码;
4. 配置tomcat,然后运行运行项目,输入localhost:8087 登录
5. 餐厅老板账户:admin 密码:admin
普通用户账户:miaosheng 密码:miaosheng
- @Controller
- public class HomeController {
- @Autowired
- private NoticeService noticeService;
- @Autowired
- private ProductService productService;
-
- @Autowired
- private LeaveService leaveService;
- @Autowired
- private EvaService evaService;
-
- /**
- * 跳转到首页
- * @param model
- * @return
- */
- @GetMapping(value = {"/","/index"})
- public String home(Model model) {
- //1-获取上架商品信息
- List<Product> productList = productService.findAllProductList()
- .stream().filter(product -> product.getStatus() == 1).collect(Collectors.toList());
- //2-获取有效的公告信息
- List<Notice> validNoticeList = noticeService.findAll()
- .stream().filter(notice -> notice.getStatus() == 1).collect(Collectors.toList());
- //3-获取热门商品信息
- List<Product> hotProductList = new ArrayList<>();
- productService.findProductBannerByCount(3).forEach(productBanner ->{
- Product dbProduct = productService.findProductById(productBanner.getProductId());
- if(dbProduct != null) { hotProductList.add(dbProduct);}
- });
- //4-查询两条评论
- List<Evaluate> evaluateList = evaService.find2Eva();
- //5-所有的商品种类名
- List productKindList = productService.findAllProductKindNameList();
- //6-用户留言表
- List<Leave> leaveList = leaveService.findAllLeaveList();
-
-
- model.addAttribute("productList",productList);
- model.addAttribute("noticeList",validNoticeList);
- model.addAttribute("hotProductList",hotProductList.stream().limit(3).collect(Collectors.toList()));
- model.addAttribute("evaluateList",evaluateList);
- model.addAttribute("productKindList",productKindList);
- model.addAttribute("leaveList",leaveList);
- return "/pages/index";
- }
- }
- @Controller
- public class UserController {
- @Autowired
- private OrderService orderService;
- @Autowired
- private UserService userService;
- @Autowired
- private EvaService evaService;
- @Autowired
- private LeaveService leaveService;
-
- /**
- * 去用户中心
- */
- @GetMapping("/toUserCenter")
- public String userCenter(Model model,HttpSession session){
- User user = (User) session.getAttribute("user");
- User userInfos = userService.findUserInfo(user.getId());
- model.addAttribute("userInfos",userInfos);
- return "/pages/user/user_center";
- }
-
- /**
- * 去我的订单
- */
- @RequestMapping("/toUserOrder")
- public String toUserOrder(@RequestParam(required=true,defaultValue="1") Integer page, HttpSession session, Model model){
- User users = (User) session.getAttribute("user");
- User user = userService.findUserInfo(users.getId());
- //PageHelper.startPage(page, pageSize);这段代码表示,程序开始分页了,page默认值是1,pageSize默认是10,意思是从第1页开始,每页显示10条记录。
- PageHelper.startPage(page, 3);
- List<Order> orderList = orderService.findOrderListByUserId(users.getId());
- PageInfo<Order> p = new PageInfo<Order>(orderList);
- model.addAttribute("page", p);
- model.addAttribute("orderList",orderList);
- model.addAttribute("user",user);
- return "/pages/user/user_orderlist";
- } /**
- * 显示收货地址
- * @param model
- * @return
- */
- @RequestMapping("/userAddress")
- public String userAddress(Model model, HttpSession session) {
-
- User user = (User) session.getAttribute("user");
- User userInfos = userService.findUserInfo(user.getId());
- model.addAttribute("userInfos",userInfos);
- return "/pages/user/user_address";
- }
- /**
- *
- *更新收货地址
- */
- @RequestMapping("/updateAddress")
- public String updateAddress(User user,Model model){
- userService.updateAddress(user);
- return "redirect:/userAddress";
- }
-
- /**
- * 显示个人中心信息
- * @param model
- * @return
- */
- @RequestMapping("/userAccount")
- public String userAccount(Model model,HttpSession session){
- User user = (User) session.getAttribute("user");
- User userInfos = userService.findUserInfo(user.getId());
- model.addAttribute("userInfos",userInfos);
- return "/pages/user/user_account";
- }
-
- /**
- * 跳转修改密码界面
- * @return
- */
- @RequestMapping("/updatePassword")
- public String updatePassword(){
- return "/pages/user/user_password";
- }
-
- /**
- * 修改密码
- * @param oldPwd 旧密码
- * @param newPwd 新密码
- * @param comfirmPwd 确认密码
- * @param model 数据
- * @return
- */
- @RequestMapping("/savePassword")
- public String saveAddress(
- String oldPwd, String newPwd, String comfirmPwd,Model model,HttpSession session){
- /* User user = (User) session.getAttribute("user");
- if(user == null){
- return "/login";
- }
- User userInfo = userService.findUserInfo(user.getUserId());
- String dbPwd = userInfo.getPassword();
- if(StringUtils.isEmpty(oldPwd) && StringUtils.isEmpty(newPwd) && StringUtils.isEmpty(comfirmPwd)){
- //输入为空
- model.addAttribute("errorInfo","输入为空!");
- return "/pages/user/user_password";
- }else if(!dbPwd.equals(oldPwd)){
- //旧密码不对
- model.addAttribute("errorInfo","旧密码不对!");
- return "/pages/user/user_password";
- }else if(!newPwd.equals(comfirmPwd)){
- //两次密码输入不一致
- model.addAttribute("errorInfo","两次输入密码不一致!");
- return "/pages/user/user_password";
- }else{
- //输入合法,进入修改密码
- userService.updatePwd(comfirmPwd);*/
- return "redirect:/userAccount";
- }
-
- /**
- * 跳转修改更换手机号界面
- * @return
- */
- @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.getId().toString());
- model.addAttribute("msg","修改成功");
- return "redirect:/userAccount";
- }
-
- /**
- * 解绑手机号
- * @return
- */
- @RequestMapping("/deleteTel")
- public String deleteTel(HttpSession session){
- User user = (User) session.getAttribute("user");
- userService.deleteTel(user.getId().toString());
- return "redirect:/userAccount";
- }
-
- /**
- * 跳转到更换邮箱界面
- * @return
- */
- @RequestMapping("/updateEmail")
- public String updateEmail(){
- return "/pages/user/user_email";
- }
-
- /**
- * 更换邮箱
- * @param newEmail 新邮箱
- * @return
- */
- @RequestMapping("/saveEmail")
- public String saveEmail(String newEmail,Model model,HttpSession session){
- String regexEmail = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
- User user = (User) session.getAttribute("user");
- if(user == null){
- return "/login";
- }
- if (!newEmail.matches(regexEmail)){
- model.addAttribute("msg","格式错误!");
- return "/pages/user/user_email";
- }
- userService.updateEmail(user.getId().toString(),newEmail);
- return "redirect:/userAccount";
- }
-
- /**
- * 修改订单状态
- * @param status
- * @param orderId
- * @return
- */
- @RequestMapping("/updateOrderStatus")
- public String updateOrderStatus(Integer status,String orderId){
- orderService.updateOrderStatus(status,orderId);
- return "redirect:/toUserOrder";
- }
-
- /**
- * 跳转评价页面
- */
- @RequestMapping("/toEvaluate")
- public String toEvaluate(String orderId,Integer status,Model model){
- List<String> productNameList = new ArrayList<>();
- orderService.findProductByOrderId(orderId).forEach((product) -> {
- productNameList.add(product.getProductName());
- });
- model.addAttribute("productNameList",productNameList);
- model.addAttribute("orderId",orderId);
- model.addAttribute("status",status);
- return "/pages/user/evaluate";
- }
-
- /**
- * 发布评论
- */
- @RequestMapping("/saveEva")
- public String saveEva(String orderId,String content,Integer status){
- evaService.saveEva(orderId,content,status);
- return "redirect:/toEvaList";
- }
-
- /**
- * 用户评价列表
- * @return
- */
- @RequestMapping("/toEvaList")
- public String toEvaList(@RequestParam(required=true,defaultValue="1") Integer page,Model model){
- PageHelper.startPage(page, 4);
- List<Evaluate> evaList = evaService.findAllEvaList();
- //PageHelper.startPage(page, pageSize);这段代码表示,程序开始分页了,page默认值是1,pageSize默认是10,意思是从第1页开始,每页显示10条记录。
- PageInfo<Evaluate> p=new PageInfo<Evaluate>(evaList);
- model.addAttribute("page", p);
- model.addAttribute("evaList",evaList);
- return "/pages/user/evaluate_list";
- }
-
- @RequestMapping("/createLeave")
- public String createLeave(String content,HttpSession session){
- User user = (User)session.getAttribute("user");
- leaveService.createLeave(content,user);
- return "redirect:/index";
- }
- @RequestMapping("/aboutUs")
- public String aboutUs(){
- return "/pages/other/about_us";
- }
- @RequestMapping("/userLogout")
- public String userLogout(HttpSession httpSession){
- //将user对象从session域中删除
- httpSession.removeAttribute("user");
- //页面应该跳转到登陆页面
- return "redirect:/index";
- }
- }
如果也想学习本系统,下面领取。回复:038springboot
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。