基于javaweb的网上订餐管理系统(java+jsp+bootstrap+jquery+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的网上订餐管理系统(java+JSP+bootstrap+jQuery+Mysql)
项目介绍
基于JSP+Servlet的网上订餐管理系统的设计与实现。该项目为前后台管理项目。 前台主要展示给普通用户,主要功能有菜品分类、最新菜品、销售排行、美食预订、营养小贴士、餐点搜索、订餐车、 在线留言等;
后台主要提供给管理员,主要功能有菜品管理、菜品类别管理、营养小贴士管理、会员管理、员工管理、留言管理、采购管理、销售订单查询、统计管理、用户管理等;
环境需要
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版本;
技术栈
- 后端:Servlet 2. 前端:JSP+bootstrap+jQuery
使用说明
- 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,下载所需jar包; 2. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 3. 将项目中DBConn.java文件中的数据库配置改为自己的配置 4. 配置tomcat,然后运行项目,输入localhost:8080/xxx 登录 5. 后台管理员账户:admin 密码:admin 前台普通用户:111 密码:111
用户管理控制层:
@Controller
public class TbUserController {
@Resource
TbUserServiceImpl tbUserService;
@GetMapping(“/toLogin”)
public String toLogin(){
return “user/login”;
@PostMapping(“/register”)
public String register(String uUsername, String uPassword, String uRole,Model model){
List users = tbUserService.selectAllUser();
for (TbUser temp : users){ //验证成功,直接登录
if(uUsername.equals(temp.getUUsername())){
model.addAttribute(“msg”,“刚刚:注册失败,该用户已存在!”);
return “user/login”;
TbUser user = new TbUser();
user.setUUsername(uUsername);
user.setUPassword(uPassword);
user.setURole(uRole);
tbUserService.insertUser(user);
model.addAttribute(“msg”,“刚刚:注册成功,赶快登录进行登录吧~”);
return “user/login”;
/插入用户数据,返回字符串信息/
@ResponseBody
@RequestMapping(“/insertUserInfo”)
public String insertUserInfo(String uUsername, String uPassword, String uRole){
//查询是否存在用户名了
String msg = “未知错误!”;
List users = tbUserService.selectUserByName(uUsername);
if(users.size() == 0){
TbUser user = new TbUser();
user.setUUsername(uUsername);
user.setUPassword(uPassword);
user.setURole(uRole); //字符串转化为int
int i = tbUserService.insertUser(user);
if(i != 0){
msg = “新添用户成功!”;
}else {
msg = “该用户名已存在,插入失败!”;
return msg;
/编辑用户信息,返回字符串信息/
@ResponseBody
@RequestMapping(“/edUserInfo”)
public String edUserInfo(TbUser user){
tbUserService.updateUserByUser(user);
return “用户数据已更新!”;
/跳转用户信息页面 + 分页/
@RequestMapping(“/userInfo”) //从1开始
public String userInfo(Model model,@RequestParam(value = “pageNum”,defaultValue = “1”)Integer pageNum){
List users = tbUserService.selectAllUser();
Page page = new Page<>(pageNum,5);
tbUserService.selectPage(page);
model.addAttribute(“users”,users);
model.addAttribute(“page”,page);
return “user/userInfo”;
/删除用户/
@RequestMapping(“/deleteUser/{uId}”)
public String deleteUser(@PathVariable(“uId”)int uId, Model model){
tbUserService.deleteUserById(uId);
model.addAttribute(“msg”,“删除成功!”);
return “redirect:/userInfo”;
@GetMapping(“/myInfo”)
public String myInfo(Principal principal,Model model){
String str = principal.getName();
List list = tbUserService.selectAllUser();
for(TbUser tbUser:list) {
if(tbUser.getUUsername().equals(str)){
model.addAttribute(“Member”,tbUser.getMember());
return “user/myInfo”;
/上传头像/
@RequestMapping(“/updateMyImg”)
public String updateMyImg(@RequestParam(value = “updateHeadImg”) MultipartFile updateHeadImg,
int uId, Model model, HttpSession session){
String imgPath = FileUpload.uploadFile(updateHeadImg);
//更新操作
TbUser user = tbUserService.selectUserById(uId);
user.setUUrl(imgPath);
tbUserService.updateUserByUser(user);
user = tbUserService.selectUserById(uId);
UpdateSession.reloadUserAuthority(session,user);
return “redirect:/myInfo”;
/更新我的信息/
@RequestMapping(“/updateMyInfo”)
public String updateMyInfo(TbUser user, HttpSession session){
//更新操作
TbUser tbUser = tbUserService.selectUserById(user.getUId()); //保存新数据,避免被原数据覆盖
System.out.println("tbUser = " + tbUser);
user.setUUsername(tbUser.getUUsername());
user.setUPassword(tbUser.getPassword());
user.setUMoney(tbUser.getUMoney());
tbUserService.updateUserByUser(user);
user = tbUserService.selectUserById(user.getUId());
UpdateSession.reloadUserAuthority(session,user);
return “redirect:/myInfo”;
@RequestMapping(“/shenqinghuiyuan”)
public String shenqinghuiyuan(Integer uId, HttpSession session,Model model){
//更新操作
//保存新数据,避免被原数据覆盖
TbUser tbUser = tbUserService.selectUserById(uId);
if(tbUser.getUMoney()>200){
tbUserService.updateMeber(uId);
model.addAttribute(“Member”,2);
model.addAttribute(“error”,“申请成功,请重新登录后方可生效”);
}else{
model.addAttribute(“error”,“未满足条件”);
model.addAttribute(“Member”,1);
return “user/myInfo”;
// @GetMapping(“/outLogin”)
// public String outLogin(HttpSession session){
// session.removeAttribute(“user”);
// return “user/login”;
// }
// @PostMapping(“/login”) 添加了安全策略不在需要手动验证,只需要提供个请求路径
// public void login(String uUsername, String uPassword, Model model, HttpSession session){
// List users = tbUserService.selectAllUser();
// for (TbUser temp : users){ //验证成功,直接登录
// if(uUsername.equals(temp.getUUsername()) && uPassword.equals(temp.getUPassword())){
// session.setAttribute(“user”,temp);
// return “redirect:/”;
// }
// if(uUsername.equals(temp.getUUsername()) && !uPassword.equals(temp.getUPassword())){
// model.addAttribute(“msg”,“刚刚:密码错误,登录失败!”);
// return “user/login”;
// }
// }
// model.addAttribute(“msg”,“刚刚:该用户不存在,请重新输入!”);
// return “user/login”;
// }
订单详情管理控制层:
@Controller
public class OrderDetailController {
@Resource
OrderDetailServiceImpl orderDetailService;
@Resource
ShoppingCartServiceImpl shoppingCartService;
@Resource
MenuDetailServiceImpl menuDetailService;
@Resource
TbUserServiceImpl tbUserService;
//修改订单状态,从0到1,由商家更新
@ResponseBody
@RequestMapping(“/changeStatusToOne”)
public String changeStatusToOne(int odId){
OrderDetail one = orderDetailService.selectOneByOdId(odId);
one.setOdStatus(1);
orderDetailService.updateOrder(one); //更新订单
return “已接单,尽快送餐吧~”;
//修改订单状态,从1到2,由用户更新
@ResponseBody
@RequestMapping(“/changeStatusToTwo”)
public String changeStatusToTwo(int odId){
OrderDetail one = orderDetailService.selectOneByOdId(odId);
one.setOdStatus(2);
orderDetailService.updateOrder(one); //更新订单
//同时更新商家的账户
TbUser adminUser = tbUserService.selectUserById(1);
int updateMoney = one.getOdTotal()+adminUser.getUMoney();
adminUser.setUMoney(updateMoney);
tbUserService.updateUserByUser(adminUser);
return “您已确认送达,钱已入商家商户,订单已完结~”;
@RequestMapping(“/orderManage”)
public String orderManage(Model model,@RequestParam(value = “pageNum”,defaultValue = “1”)Integer pageNum){
List orders = orderDetailService.selectAll();
Collections.reverse(orders); //倒叙
Page page = new Page<>(pageNum,10);
orderDetailService.selectPage(page); //分页
int allCount = orders.size(); //总数
int pendingCount = 0; //待处理单数
int receivedCount = 0; //待已接单数
int finishCount = 0; //已完结
for (OrderDetail order : orders){
if(order.getOdStatus() == 0){
pendingCount += 1;
}else if(order.getOdStatus() == 1){
receivedCount += 1;
}else{
finishCount += 1;
TbUser adminUser = tbUserService.selectUserById(1);
model.addAttribute(“total”,adminUser.getUMoney());
model.addAttribute(“page”,page);
model.addAttribute(“orders”,orders);
model.addAttribute(“allCount”,allCount);
model.addAttribute(“pendingCount”,pendingCount);
model.addAttribute(“receivedCount”,receivedCount);
model.addAttribute(“finishCount”,finishCount);
return “menu/orderManage”;
@RequestMapping(“/myOrder”)
public String myOrder(Model model,int uId){
List myOrders = orderDetailService.selectAllOrderByUId(uId);
TbUser user = tbUserService.selectUserById(uId);
model.addAttribute(“myOrders”,myOrders);
model.addAttribute(“total”,user.getUMoney());
return “user/myOrder”;
@ResponseBody
@PostMapping(“/toOrder”)
public String toOrder(OrderDetail orderDetail){
TbUser user = tbUserService.selectUserById(orderDetail.getUId());
//查询当前用户的所以购物车
List carts = shoppingCartService.selectAllByUId(orderDetail.getUId());
//获取到具体商品
String odDetail = “【”;
int odTotal = 0;
for (ShoppingCart cart : carts){
odDetail += cart.getScName()+" × “+cart.getScAmount()+”;"; //拼接成:米饭 × 1;格式
odTotal += cart.getScPrice()*cart.getScAmount(); //数量×价格
odDetail += “】”;
//赋值
orderDetail.setOdDetail(odDetail);
if(user.getMember()==2){
orderDetail.setOdTotal((int)(odTotal * 0.88));
}else{
orderDetail.setOdTotal(odTotal);
orderDetail.setOdStatus(0);
orderDetail.setOdNo(RandomNo.getRandomNo());
//完成插入
orderDetailService.insertOrder(orderDetail);
//清空购物车 + 更新商品数据
for (ShoppingCart cart : carts){
shoppingCartService.deleteById(cart.getScId()); //删除购物车数据
MenuDetail menuDetail = menuDetailService.selectById(cart.getMdId()); //通过产品id获得产品
menuDetail.setMdAmount(menuDetail.getMdAmount()-cart.getScAmount()); //减去下单数量
menuDetailService.updateMenu(menuDetail); //更新产品数据
TbUser User= tbUserService.selectUserById(orderDetail.getUId()); //用户更新支付金额
System.out.println(odTotal+“=============”);
System.out.println(user.getMember()+“=====”+odTotal);
if(user.getMember()==1 && odTotal>200) {//当会员为1时,说明不是会员,并且支付的金额大于200
user.setMember(2);
System.out.println(“进入方法后”+user.getMember());
user.setUMoney(user.getUMoney()+odTotal);
System.out.println(user.getMember());
tbUserService.updateUserByUser(user);
List details = orderDetailService.selectAllOrderByUId(orderDetail.getUId());
for (OrderDetail detail : details){
System.out.println("detail = " + detail.getOdCreateTime());
return “下单成功~”;
菜单详情控制层:
@Controller
public class MenuDetailController {
@Resource
MenuDetailServiceImpl menuDetailService;
@Resource
MenuTypeServiceImpl menuTypeService;
@Resource
FileUpload fileUpload;
/主页/ /*联合查询,根据menuId查询 */
@RequestMapping({“/main”,“/”,“/index”})
public String main(Model model,HttpSession session){
//用于封装整合后的对象的集合
List menus = new ArrayList();
List types = menuTypeService.selectAllType(); //查询出所有类型对象
//临时集合,用于存放需要移除的,0菜品的类型对象
List temp = new ArrayList();
//通过mt_id重新封装对象列表
for (MenuType type : types){
List menu = menuDetailService.selectByType(type.getMtId());
//如果 当前分类没有菜品,则移除该分类,同时不添加
if (menu.size() == 0){
temp.add(type);
menus.addAll(menu);
//封装后的list
model.addAttribute(“menus”,menus);
//移除空的类型
for (MenuType t : temp){
types.remove(t);
model.addAttribute(“types”,types);
return “main”;
/菜单管理 分页/ /新增模糊查询分页/
@RequestMapping(“/menuManage”)
public String menuManage(@RequestParam(value = “mtId”,defaultValue = “0”) int mtId,
@RequestParam(value = “pageNum”,defaultValue = “1”) Integer pageNum,
@RequestParam(value = “msg”,defaultValue = “no”) String msg, //上传图片传过来的值
@RequestParam(value = “search”,defaultValue = “no”) String search,
Model model){
Page page = new Page<>(pageNum,3);
//根据mtId进行分页。 mtId=0 默认显示全部
menuDetailService.selectPage(page,mtId);
//根据搜索名分页,覆盖原来的page;
if(!search.equals(“no”)) {
menuDetailService.selectPageByName(page,search);
msg = “searchSuccess”;
model.addAttribute(“page”,page);
List types = menuTypeService.selectAllType();
model.addAttribute(“types”,types);
model.addAttribute(“mtId”,mtId); //激活标签
model.addAttribute(“msg”,msg);
return “menu/menuManage”;
/删除单品/
@RequestMapping(“/deleteOneMenu/{mdId}/{mtId}”)
public String deleteOneMenu(@PathVariable(value = “mdId”)int mdId, @PathVariable(value = “mtId”)int mtId){
int i = menuDetailService.deleteOneMenu(mdId);
return “redirect:/menuManage?mtId=” + mtId;
/上传图片/
@RequestMapping(“/upLoadImg”)
public String upLoadImg(@RequestParam(value = “upLoadFile”) MultipartFile upLoadFile,
@RequestParam(value = “mdId”)int mdId,
@RequestParam(value = “mtId”)int mtId, Model model){
String msg = null;
String imgPath = FileUpload.uploadFile(upLoadFile);
//更新操作
MenuDetail menuDetail = menuDetailService.selectById(mdId);
System.out.println("menuDetail = " + menuDetail.getMdName());
menuDetail.setMdUrl(imgPath);
menuDetailService.updateMenu(menuDetail);
if(imgPath == null){
msg = “uploadFault”;
return “redirect:/menuManage?mtId=”+mtId+“&msg=”+msg;
System.out.println("imgPath = " + imgPath);
msg = “uploadSuccess”;
return “redirect:/menuManage?mtId=”+mtId+“&msg=”+msg;
@ResponseBody
@RequestMapping(“/insertMenu”)
public String insertMenu(MenuDetail menuDetail){
menuDetailService.insertMenu(menuDetail);
return “已成功新添菜品:”+menuDetail.getMdName();
@ResponseBody
@RequestMapping(“/updateMenu”)
public String updateMenu(MenuDetail menuDetail){
MenuDetail tempMenu = menuDetailService.selectById(menuDetail.getMdId()); //原来数据库中的数据
tempMenu.setMdName(menuDetail.getMdName());
tempMenu.setMdPrice(menuDetail.getMdPrice());
tempMenu.setMdAmount(menuDetail.getMdAmount());
tempMenu.setMdNew(menuDetail.getMdNew());
tempMenu.setMdStar(menuDetail.getMdStar());
tempMenu.setMtId(menuDetail.getMtId()); //重新赋值
menuDetailService.updateMenu(tempMenu);
return menuDetail.getMdName()+“更新成功!”;