作者主页:Java毕设网
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
一、相关文档
自助售货机在日常生活中已经屡见不鲜,随处即是的它们方便了人们的生活,节约了人们宝贵的时间。随着人们物质生活水平的提高,自助售货机应该呈现出不同的类别,适用于不同的环境。本组开发的自助售货机使人们的生活更方便,更快捷。
自助售货系统主要从员工、维修人员和补货人员三个角色进行设计,以下分别说明了三类角色的不同功能和访问权限。
二、项目介绍
自助售货管理系统,该系统分为前后台,两个项目,前台项目为autosale-1,后台项目为automanager1;启动时需要先启动automanager1,再启动autosale-1,否则会造成启动不成功的问题;
前台主要功能包括:
轮播图展示、商品列表、支付宝沙箱环境支付,注:需要配置自己的沙箱环境;
后台主要包括三种角色:管理员、维修员、补货员;
管理员主要功能包括:
员工管理、商品管理、商品类型管理、设备管理、销售报表、财务统计;
注:autosale默认启动的贩卖机编号为21,若想要添加商品,首先在商品管理中添加商品;然后在设备管理中,找到贩卖机编号为21的,查看设备状态是否为正常,若为正常,则点击管理设备按钮,然后点击上架,选择需要上架的商品即可;
维修员主要功能包括:
待维修请求处理、全部维修信息、所属设备列表;
补货员主要功能包括:
待补货请求处理、全部补货请求信息、所属设备列表;
三、环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
4.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
5.数据库:MySql 5.7版本;
6.Zookeeper;
四、技术栈
1. 后端:SpringBoot + DUBBO
2. 前端:JSP+bootstrap+jQuery
五、使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应sql文件名称的数据库,并导入项目的sql文件;
2. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
3. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
4. 分别运行项目,售卖端输入http://localhost:8080/autosale/ 登录
管理端输入:http://localhost:8088/autom/
六、运行截图
前台页面
后台页面
七、相关代码
登录管理控制器
package com.kyj.controller;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.kyj.po.Replenishemp;
import com.kyj.po.Serviceemp;
import com.kyj.po.User;
import com.kyj.service.IServiceempService;
import com.kyj.service.ReplenishempService;
import com.kyj.service.UserService;
/**
* @author YX
* @category 后台首页控制器
*/
@Controller
public class LoginController {
@Autowired
private UserService userService;
@Autowired
private IServiceempService iServiceempService;
@Autowired
private ReplenishempService replenishempService;
@RequestMapping({"/","/tologin"})
public String tologin(Model model) {
return "forward:/statics/login.jsp";
}
@RequestMapping("/login")
public String login(@RequestParam(value="id",required=false)int id,@RequestParam(value="password",required=false)String password, @RequestParam(value="type",required=false)int type,HttpSession session,Model model) {
if(type==1) {//管理员登录
int uid = id;
User user = userService.findUser(uid, password);
if(user !=null) {
session.setAttribute("currentUser", user);
return "index";
}else {
model.addAttribute("msg", "登录失败请检查用户名和密码是否正确!");
return "forward:/statics/login.jsp";
}
}else if(type==2) {//维修员登录
int sid = id;
Serviceemp serviceemp = iServiceempService.findServiceemp(sid, password);
if(serviceemp !=null) {
session.setAttribute("serviceemp", serviceemp);
return "updater/nav_serviceemp";
}else {
model.addAttribute("msg", "登录失败请检查用户名和密码是否正确!");
return "forward:/statics/login.jsp";
}
}else if(type==3) {//补货员登录
int rid =id;
Replenishemp replenishemp =replenishempService.findReplenishemp(rid, password);
if(replenishemp !=null) {
session.setAttribute("replenishemp", replenishemp);
return "addgooder/nav_replenishemp";
}else {
model.addAttribute("msg", "登录失败请检查用户名和密码是否正确!");
return "forward:/statics/login.jsp";
}
}else {
model.addAttribute("msg", "登录失败请检查用户名和密码是否正确!");
return "forward:/statics/login.jsp";
}
}
}
商品管理控制器
package com.kyj.controller;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import javax.websocket.server.PathParam;
import com.kyj.util.Escape;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.kyj.po.Goods;
import com.kyj.po.Page;
import com.kyj.service.IGoodsService;
import com.kyj.vo.GoodsVO;
/**
* @author zxh
* @category 商品类控制器
*/
@Controller
@RequestMapping("/goods")
public class GoodsController {
@Autowired
private IGoodsService igoodsService;
@Autowired
private Page page;
/**
* @category 商品列表展示控制器
* @param model
* @param currentPage1
* @param pageSize1
* @return
*/
@RequestMapping("/showgoodslist")
public String findGoodsList(Model model, @RequestParam(value = "pageNum", required = false) String currentPage1,
@RequestParam(value = "pagesize", required = false) String pageSize1) {
int currentPage = currentPage1 == null ? 1 : Integer.valueOf(currentPage1);
int pageSize = pageSize1 == null ? 10 : Integer.valueOf(pageSize1);
int listCount = igoodsService.getGoodsPageCount();
List<GoodsVO> list = igoodsService.findGoodsList(currentPage, pageSize);
page.setValue(currentPage, pageSize, listCount);
model.addAttribute("page", page);
model.addAttribute("list", list);
System.out.println(list.size());
for (GoodsVO goodsVO : list) {
System.out.println(goodsVO.getGname());
}
return "goods/goods";
}
/**
* @category 查询所有商品控制器
* @return
*/
@RequestMapping("/findallgoods")
public @ResponseBody List<GoodsVO> findAllGoods() {
List<GoodsVO> list = igoodsService.findAllGoods();
return list;
}
/**
* @category 通过商品编号查询商品控制器
* @param gid
* @return
*/
@RequestMapping("/findbygid")
public @ResponseBody GoodsVO findById(Integer gid) {
GoodsVO goodsVO = igoodsService.findById(gid);
return goodsVO;
}
/**
* @category 通过商品名查询商品控制器
* @param gname
* @return
*/
@RequestMapping("/findbygname")
public @ResponseBody GoodsVO findByGName(String gname) {
GoodsVO goodsVO = igoodsService.findByName(gname);
return goodsVO;
}
/**
* @category 通过商品名查询商品控制器,并跳转到商品详情页
* @param gname
* @return
*/
@RequestMapping("/findByName")
public String findByName(Model model,String gname) {
gname = gname.replaceAll(" ", "%2B");
GoodsVO goodsVO = igoodsService.findByName(Escape.unescape(gname));
model.addAttribute("gvo", goodsVO);
return "goods/goodsInfo";
}
/**
* @category 删除商品控制器
* @param gid
* @return
*/
@RequestMapping("/deletebygid")
public String deleteById(Integer gid) {
igoodsService.deleteById(gid);
return "redirect:/goods/showgoodslist";
}
/**
* @category 跳转修改商品界面控制器
* @param model
* @param gid
* @return
*/
@RequestMapping("/toupdategoods")
public String update(Model model, @PathParam("gid") Integer gid) {
GoodsVO goodsVO = igoodsService.findById(gid);
model.addAttribute("gvo", goodsVO);
return "goods/updategoods";
}
/**
* @category 修改商品信息控制器
* @param goods
* @return
*/
@RequestMapping("/updategoods")
public String updateSave(Goods goods) {
igoodsService.update(goods);
return "forward:showgoodslist.action";
}
/**
* @category 添加商品控制器
* @param goods
* @return
* @throws IOException
* @throws IllegalStateException
*/
@RequestMapping("/addgoods")
public String insertGoods(Goods goods, Model model) throws IllegalStateException, IOException {
// 保存数据库的路径
String sqlPath = null;
// 定义autosale-1/src/main/webapp/static/images/的本地路径 windows系统参考此修改;
//String localPath = "D:\\autosale-1\\src\\main\\webapp\\static\\images\\";
// 定义autosale-1/src/main/webapp/static/images/的本地路径 Mac系统参考此修改;
String localPath = "/Users/hanmeng/Desktop/java源码/Springboot/019springboot自助售货管理系统(含报告)/源码/autosale-1/src/main/webapp/static/images/";
// 定义文件名
String filename = null;
if (!goods.getFile().isEmpty()) {
// 生成uuid作为文件名
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
// 获得文件类型(可以判断如果不是图片,禁止上传)
String contentType = goods.getFile().getContentType();
// 获得文件后缀名
String suffixName = contentType.substring(contentType.indexOf("/") + 1);
// 得到文件名
filename = uuid + "." + suffixName;
// 文件保存路径
goods.getFile().transferTo(new File(localPath + filename));
}
// 把图片的相对路径保存至数据库
sqlPath = "/images/" + filename;
System.out.println(sqlPath);
goods.setImg(sqlPath);
igoodsService.insertGoods(goods);
model.addAttribute("goods", goods);
return "forward:showgoodslist.action";
}
}