基于javaweb+mysql的ssm超市订单管理系统(java+ssm+jsp+bootstrap+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM超市订单管理系统(java+ssm+jsp+bootstrap+mysql)
项目介绍
超市订单管理系统。主要功能包括订单管理、供应商管理、用户管理等功能;
环境需要
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版本;
技术栈
- 后端:Spring SpringMVC MyBatis 2. 前端:JSP+bootstrap+jQuery
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 将项目中applicationContext-jdbc.xml配置文件中的数据库配置改为自己的配置 3. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行; 4. 运行项目,输入localhost:8080/ssm8/login 登录;其中ss8为项目名称,可自定义,但后面路径必须为/login;
md.addAttribute("provider", provider);
return "modifyProvider";
}
//修改供应商
@RequestMapping("/modifyProviderGo")
public String modifyProviderGo(Provider provider,HttpSession session) {
Integer oid=((User)session.getAttribute(Constants.USER_SESSION)).getId();
if(null!=provider) {
provider.setModifyBy(oid);
provider.setModifyDate(new Date());
proService.modifyProvider(provider);
}
return "redirect:getProviders";
}
//从ID获取某一个供应商信息
@RequestMapping("/viewProvider")
public String viewProvider(String id,Model md) {
Provider provider=new Provider();
provider=proService.getProvider(id);
md.addAttribute("provider", provider);
return "viewProvider";
}
//删除供应商
@RequestMapping("deleteProviderById")
public String deleteProviderById(String id,Model md) {
String msg="";
if(proService.deleteProviderById(id)) {
msg="删除订单成功!";
}else
msg="删除订单失败!";
md.addAttribute("msg", msg);
return "redirect:getProviders";
}
}
msg="删除订单成功!";
}else
msg="删除订单失败!";
md.addAttribute("msg", msg);
return "redirect:getOrder";
}
//添加修改界面
@RequestMapping("/modifyOrder")
public String modifyOrder(String id,Model md) {
Order order=new Order();
order=orderService.getOrderById(id);
md.addAttribute("order", order);
return "modifyOrder";
}
//添加修改用户的执行路由信息
@RequestMapping("/modifyOrderGo")
public String modifyOrderGo(Order order,HttpSession session) {
Integer oid=((User)session.getAttribute(Constants.USER_SESSION)).getId();
if(null!=order) {
order.setModifyBy(oid);
order.setModifyDate(new Date());
orderService.modifyOrder(order);
}
return "redirect:getOrder";
}
//根据ID查看订单
@RequestMapping("/viewOrder")
public String viewOrder(String id,Model md) {
Order order=new Order();
order=orderService.getOrderById(id);
md.addAttribute("order", order);
return "viewOrder";
}
}
@Controller
public class IndexController{
//用户登录处理界面
return "redirect:login";
}
//添加供应商界面
@RequestMapping("/providerAdd")
public String providerAdd() {
return "providerAdd";
}
@RequestMapping("/getProviders")
public String getProviderList(String proName,Model md,String pageIndex) {
String strName="";
if(!StringUtils.isEmpty(proName)) {
strName=proName;
}
Integer currentPageNo=1;
Integer pageSize=Constants.pageSize;
if(!StringUtils.isEmpty(pageIndex)) {
currentPageNo=Integer.parseInt(pageIndex);
}
//根据条件获取总记录数
Integer totalCount=proService.getProviderCount(strName);
//计算可以分几页
PageHelper pages=new PageHelper();
pages.setCurrentPageNo(currentPageNo);
pages.setPageSize(pageSize);
pages.setTotalCount(totalCount);
int totalPageCount = pages.getTotalPageCount();
List<Provider> providers=proService.getProviderList(strName,(currentPageNo-1)*pageSize,pageSize);
md.addAttribute("totalPageCount", totalPageCount);
md.addAttribute("totalCount", totalCount);
md.addAttribute("currentPageNo", currentPageNo);
md.addAttribute("providers",providers);
return "providerList";
}
//添加修改界面
@RequestMapping("/modifyProvider")
public String modifyProvider(String id,Model md) {
Provider provider=new Provider();
provider=proService.getProvider(id);
md.addAttribute("provider", provider);
return "modifyProvider";
}
//修改供应商
@RequestMapping("/modifyProviderGo")
public String modifyProviderGo(Provider provider,HttpSession session) {
Integer oid=((User)session.getAttribute(Constants.USER_SESSION)).getId();
if(null!=provider) {
provider.setModifyBy(oid);
provider.setModifyDate(new Date());
proService.modifyProvider(provider);
}
return "redirect:getProviders";
}
//总页数
PageHelper pages=new PageHelper();
pages.setCurrentPageNo(currentPageNo);
pages.setPageSize(pageSize);
pages.setTotalCount(totalCount);
int totalPageCount = pages.getTotalPageCount();
//控制首页和尾页
if(currentPageNo < 1){
currentPageNo = 1;
}else if(currentPageNo > totalPageCount){
currentPageNo = totalPageCount;
}
if(StringUtils.isEmpty(userName)) {
userName="";
}
List<User> users=userService.getUserList(userName,roleName,(currentPageNo-1)*pageSize,pageSize);
md.addAttribute("userList", users);
md.addAttribute("totalPageCount", totalPageCount);
md.addAttribute("totalCount", totalCount);
md.addAttribute("currentPageNo", currentPageNo);
return "userList";
}
@RequestMapping("/viewUser")
public String viewUser(String id,Model md) {
User user=new User();
user=userService.getUserById(id);
md.addAttribute("user", user);
return "viewUser";
}
}
@Controller
public class UserController {
@Resource
UserService userService;
//更据id删除用户信息
@RequestMapping("deleteUserById")
public String deleteUserById(String id,Model md) {
String msg="";
if(userService.deleteUserById(id)) {
msg="删除用户成功!";
}else
msg="删除用户失败!";
md.addAttribute("msg", msg);
return "redirect:getUserList";
}
//添加修改用户的执行路由信息
@RequestMapping("/modifyUserGo")
public String modifyUserGo(User user,HttpSession session) {
Integer uid=((User)session.getAttribute(Constants.USER_SESSION)).getId();
if(null!=user) {
user.setModifyBy(uid);
user.setModifyDate(new Date());
userService.modifyUser(user);
}
return "redirect:getUserList";
}
//添加修改用户的界面路由
@RequestMapping("/modifyUser")
public String modifyUser(String id,Model md) {
User user=new User();
user=userService.getUserById(id);
md.addAttribute("user", user);
return "modifyUser";
}
md.addAttribute("currentPageNo", currentPageNo);
md.addAttribute("providers",providers);
return "providerList";
}
//添加修改界面
@RequestMapping("/modifyProvider")
public String modifyProvider(String id,Model md) {
Provider provider=new Provider();
provider=proService.getProvider(id);
md.addAttribute("provider", provider);
return "modifyProvider";
}
//修改供应商
@RequestMapping("/modifyProviderGo")
public String modifyProviderGo(Provider provider,HttpSession session) {
Integer oid=((User)session.getAttribute(Constants.USER_SESSION)).getId();
if(null!=provider) {
provider.setModifyBy(oid);
provider.setModifyDate(new Date());
proService.modifyProvider(provider);
}
return "redirect:getProviders";
}
//从ID获取某一个供应商信息
@RequestMapping("/viewProvider")
public String viewProvider(String id,Model md) {
Provider provider=new Provider();
provider=proService.getProvider(id);
md.addAttribute("provider", provider);
return "viewProvider";
}
//删除供应商
@RequestMapping("deleteProviderById")
public String deleteProviderById(String id,Model md) {
String msg="";
if(proService.deleteProviderById(id)) {
msg="删除订单成功!";
}else
msg="删除订单失败!";
md.addAttribute("msg", msg);
return "redirect:getProviders";
}
}
if(userService.addUser(user1))
return "redirect:getUserList";
else {
md.addAttribute("error","您还没有登录,请登录!");
return "redirect:addUser";
}
}
else
return "redirect:login";
}
//添加用户界面
@RequestMapping("addUser")
public String addUser() {
return "addUser";
}
//请求登录界面
@RequestMapping("/login")
public String login() {
return "login";
}
//退出界面
@RequestMapping("/logout")
public String logout(HttpSession session){
session.removeAttribute("user");
return "login";
}
//请求处理程序
@RequestMapping("/loginGo")
public String loginGo(String userCode,String userPassword,Model md,HttpSession session) {
User user=new User();
user=userService.checkLogin(userCode, userPassword);
if(null!=user) {
md.addAttribute("user",user);
session.setAttribute(Constants.USER_SESSION, user);
return "frame";
}else {
//md.addAttribute("msg","用户名或密码错误!");
throw new RuntimeException("用户名或密码错误!");
//return "login";
}
}
//异常处理
// @ExceptionHandler(value= {RuntimeException.class})
// public String handlerException(RuntimeException e,HttpServletRequest req) {
// req.setAttribute("e", e);
// return "error";
// }
@RequestMapping("/main")
public String main(HttpSession session) {
//检查是否登录
if(session.getAttribute("user")==null) {
return "redirect:login";
}
md.addAttribute("totalCount", totalCount);
md.addAttribute("currentPageNo", currentPageNo);
md.addAttribute("providers",providers);
return "providerList";
}
//添加修改界面
@RequestMapping("/modifyProvider")
public String modifyProvider(String id,Model md) {
Provider provider=new Provider();
provider=proService.getProvider(id);
md.addAttribute("provider", provider);
return "modifyProvider";
}
//修改供应商
@RequestMapping("/modifyProviderGo")
public String modifyProviderGo(Provider provider,HttpSession session) {
Integer oid=((User)session.getAttribute(Constants.USER_SESSION)).getId();
if(null!=provider) {
provider.setModifyBy(oid);
provider.setModifyDate(new Date());
proService.modifyProvider(provider);
}
return "redirect:getProviders";
}
//从ID获取某一个供应商信息
@RequestMapping("/viewProvider")
public String viewProvider(String id,Model md) {
Provider provider=new Provider();
provider=proService.getProvider(id);
md.addAttribute("provider", provider);
return "viewProvider";
}
//删除供应商
@RequestMapping("deleteProviderById")
public String deleteProviderById(String id,Model md) {
String msg="";
if(proService.deleteProviderById(id)) {
msg="删除订单成功!";
}else
msg="删除订单失败!";
md.addAttribute("msg", msg);
return "redirect:getProviders";
}
}
@Controller
public class OrderController {
//引入业务层的资源
@Autowired
OrderService orderService;
//添加订单界面
@RequestMapping("/orderAdd")
public String orderAdd() {
return "orderAdd";
}
//添加订单处理方法
@RequestMapping("/orderAddGo")
public String orderAddGo(Order order,HttpSession session) {
Order ord = new Order();
ord = order;
Integer oid=null;
oid=((User) session.getAttribute(Constants.USER_SESSION)).getId();
if(null!=oid) {
ord.setCreatedBy(oid);
if(orderService.orderAdd(ord))
return "redirect:getOrder";
else
return "redirect:orderAdd";
}
else
return "redirect:login";
}
//获取订单列表的处理方法
@RequestMapping("/getOrder")
public String getOrderList(String orderName,Model md,String pageIndex) {
String strName="";
if(!StringUtils.isEmpty(orderName)) {
strName=orderName;
}
Integer currentPageNo=1;
Integer pageSize=Constants.pageSize;
if(!StringUtils.isEmpty(pageIndex)) {
currentPageNo=Integer.parseInt(pageIndex);
}
//根据条件获取总记录数
Integer totalCount=orderService.getOrderCount(strName);
//计算可以分几页
PageHelper pages=new PageHelper();
pages.setCurrentPageNo(currentPageNo);
pages.setPageSize(pageSize);
pages.setTotalCount(totalCount);
int totalPageCount = pages.getTotalPageCount();
List<Order> order=orderService.getOrderList(strName,(currentPageNo-1)*pageSize,pageSize);
md.addAttribute("totalPageCount", totalPageCount);
md.addAttribute("totalCount", totalCount);
md.addAttribute("currentPageNo", currentPageNo);
md.addAttribute("order",order);
uid=((User) session.getAttribute(Constants.USER_SESSION)).getId();
if(null!=uid) {
pro.setCreatedBy(uid);
if(proService.providerAdd(pro))
return "redirect:getProviders";
else
return "redirect:providerAdd";
}
else
return "redirect:login";
}
//添加供应商界面
@RequestMapping("/providerAdd")
public String providerAdd() {
return "providerAdd";
}
@RequestMapping("/getProviders")
public String getProviderList(String proName,Model md,String pageIndex) {
String strName="";
if(!StringUtils.isEmpty(proName)) {
strName=proName;
}
Integer currentPageNo=1;
Integer pageSize=Constants.pageSize;
if(!StringUtils.isEmpty(pageIndex)) {
currentPageNo=Integer.parseInt(pageIndex);
}
//根据条件获取总记录数
Integer totalCount=proService.getProviderCount(strName);
//计算可以分几页
PageHelper pages=new PageHelper();
pages.setCurrentPageNo(currentPageNo);
pages.setPageSize(pageSize);
pages.setTotalCount(totalCount);
int totalPageCount = pages.getTotalPageCount();
List<Provider> providers=proService.getProviderList(strName,(currentPageNo-1)*pageSize,pageSize);
md.addAttribute("totalPageCount", totalPageCount);
md.addAttribute("totalCount", totalCount);
md.addAttribute("currentPageNo", currentPageNo);
md.addAttribute("providers",providers);
return "providerList";
}
//添加修改界面
@RequestMapping("/modifyProvider")
public String modifyProvider(String id,Model md) {
Provider provider=new Provider();
provider=proService.getProvider(id);
md.addAttribute("provider", provider);
return "modifyProvider";
}
//修改供应商
PageHelper pages=new PageHelper();
pages.setCurrentPageNo(currentPageNo);
pages.setPageSize(pageSize);
pages.setTotalCount(totalCount);
int totalPageCount = pages.getTotalPageCount();
List<Order> order=orderService.getOrderList(strName,(currentPageNo-1)*pageSize,pageSize);
md.addAttribute("totalPageCount", totalPageCount);
md.addAttribute("totalCount", totalCount);
md.addAttribute("currentPageNo", currentPageNo);
md.addAttribute("order",order);
return "orderList";
}
//根据id删除订单信息
@RequestMapping("deleteOrderById")
public String deleteOrderById(String id,Model md) {
String msg="";
if(orderService.deleteOrderById(id)) {
msg="删除订单成功!";
}else
msg="删除订单失败!";
md.addAttribute("msg", msg);
return "redirect:getOrder";
}
//添加修改界面
@RequestMapping("/modifyOrder")
public String modifyOrder(String id,Model md) {
Order order=new Order();
order=orderService.getOrderById(id);
md.addAttribute("order", order);
return "modifyOrder";
}
//添加修改用户的执行路由信息
@RequestMapping("/modifyOrderGo")
public String modifyOrderGo(Order order,HttpSession session) {
Integer oid=((User)session.getAttribute(Constants.USER_SESSION)).getId();
if(null!=order) {
order.setModifyBy(oid);
order.setModifyDate(new Date());
orderService.modifyOrder(order);
}
return "redirect:getOrder";
}
//根据ID查看订单
@RequestMapping("/viewOrder")
public String viewOrder(String id,Model md) {
//return "login";
}
}
//异常处理
// @ExceptionHandler(value= {RuntimeException.class})
// public String handlerException(RuntimeException e,HttpServletRequest req) {
// req.setAttribute("e", e);
// return "error";
// }
@RequestMapping("/main")
public String main(HttpSession session) {
//检查是否登录
if(session.getAttribute("user")==null) {
return "redirect:login";
}
return "main";
}
//查询用户列表
@RequestMapping("/getUserList")
public String getUserList(String userName,String roleName,String pageIndex,Model md) {
//设置页面容量
int pageSize = Constants.pageSize;
//当前页码
int currentPageNo = 1;
if(pageIndex != null){
try{
currentPageNo = Integer.valueOf(pageIndex);
}catch(NumberFormatException e){
return "redirect:/user/syserror.html";
//response.sendRedirect("syserror.jsp");
}
}
//总数量(表)
if(StringUtils.isEmpty(userName))
userName="";
if(StringUtils.isEmpty(roleName))
roleName="";
int totalCount = userService.getUserCount(userName, roleName);
//总页数
PageHelper pages=new PageHelper();
pages.setCurrentPageNo(currentPageNo);
pages.setPageSize(pageSize);
return "redirect:/user/syserror.html";
//response.sendRedirect("syserror.jsp");
}
}
//总数量(表)
if(StringUtils.isEmpty(userName))
userName="";
if(StringUtils.isEmpty(roleName))
roleName="";
int totalCount = userService.getUserCount(userName, roleName);
//总页数
PageHelper pages=new PageHelper();
pages.setCurrentPageNo(currentPageNo);
pages.setPageSize(pageSize);
pages.setTotalCount(totalCount);
int totalPageCount = pages.getTotalPageCount();
//控制首页和尾页
if(currentPageNo < 1){
currentPageNo = 1;
}else if(currentPageNo > totalPageCount){
currentPageNo = totalPageCount;
}
if(StringUtils.isEmpty(userName)) {
userName="";
}
List<User> users=userService.getUserList(userName,roleName,(currentPageNo-1)*pageSize,pageSize);
md.addAttribute("userList", users);
md.addAttribute("totalPageCount", totalPageCount);
md.addAttribute("totalCount", totalCount);
md.addAttribute("currentPageNo", currentPageNo);
return "userList";
}
@RequestMapping("/viewUser")
public String viewUser(String id,Model md) {
User user=new User();
user=userService.getUserById(id);
md.addAttribute("user", user);
return "viewUser";
}
}
}
//异常处理
// @ExceptionHandler(value= {RuntimeException.class})
// public String handlerException(RuntimeException e,HttpServletRequest req) {
// req.setAttribute("e", e);
// return "error";
// }
@RequestMapping("/main")
public String main(HttpSession session) {
//检查是否登录
if(session.getAttribute("user")==null) {
return "redirect:login";
}
return "main";
}
//查询用户列表
@RequestMapping("/getUserList")
public String getUserList(String userName,String roleName,String pageIndex,Model md) {
//设置页面容量
int pageSize = Constants.pageSize;
//当前页码
int currentPageNo = 1;
if(pageIndex != null){
try{
currentPageNo = Integer.valueOf(pageIndex);
}catch(NumberFormatException e){
return "redirect:/user/syserror.html";
//response.sendRedirect("syserror.jsp");
}
}
//总数量(表)
if(StringUtils.isEmpty(userName))
userName="";
if(StringUtils.isEmpty(roleName))
roleName="";
int totalCount = userService.getUserCount(userName, roleName);
//总页数
PageHelper pages=new PageHelper();
pages.setCurrentPageNo(currentPageNo);
pages.setPageSize(pageSize);
pages.setTotalCount(totalCount);
int totalPageCount = pages.getTotalPageCount();
//控制首页和尾页
if(currentPageNo < 1){
currentPageNo = 1;
}else if(currentPageNo > totalPageCount){
currentPageNo = totalPageCount;
}
if(StringUtils.isEmpty(userName)) {
userName="";
}
List<User> users=userService.getUserList(userName,roleName,(currentPageNo-1)*pageSize,pageSize);
}
//根据ID查看订单
@RequestMapping("/viewOrder")
public String viewOrder(String id,Model md) {
Order order=new Order();
order=orderService.getOrderById(id);
md.addAttribute("order", order);
return "viewOrder";
}
}
@Controller
public class IndexController{
//用户登录处理界面
@RequestMapping("/userLoginGo")
public ModelAndView userLoginGo(User user,HttpSession session) {
ModelAndView mv =new ModelAndView();
mv.addObject("user",user);
session.setAttribute("userName","ddd");
mv.setViewName("success");
return mv;
}
//用户登录界面
@RequestMapping("/userLogin")
public String userLogin() {
return "userLogin";
}
@RequestMapping("/input")
public String input() {
return "input";
}
//@RequestMapping({"/index","/","/my"})
@RequestMapping(value="/index",method=RequestMethod.GET)
public String index(@RequestParam(value="username",required=false) String username,Model md) {
System.out.println("Hello SpringMVC");
md.addAttribute("username",username);
return "index";
}
@RequestMapping("/welcome")
public ModelAndView welcome(String username) {
ModelAndView mv=new ModelAndView();
@Controller
public class OrderController {
//引入业务层的资源
@Autowired
OrderService orderService;
//添加订单界面
@RequestMapping("/orderAdd")
public String orderAdd() {
return "orderAdd";
}
//添加订单处理方法
@RequestMapping("/orderAddGo")
public String orderAddGo(Order order,HttpSession session) {
Order ord = new Order();
ord = order;
Integer oid=null;
oid=((User) session.getAttribute(Constants.USER_SESSION)).getId();
if(null!=oid) {
ord.setCreatedBy(oid);
if(orderService.orderAdd(ord))
return "redirect:getOrder";
else
return "redirect:orderAdd";
}
else
return "redirect:login";
}
//获取订单列表的处理方法
@RequestMapping("/getOrder")
public String getOrderList(String orderName,Model md,String pageIndex) {
String strName="";
if(!StringUtils.isEmpty(orderName)) {
strName=orderName;
}
Integer currentPageNo=1;
Integer uid=null;
uid=((User) session.getAttribute(Constants.USER_SESSION)).getId();
if(null!=uid) {
pro.setCreatedBy(uid);
if(proService.providerAdd(pro))
return "redirect:getProviders";
else
return "redirect:providerAdd";
}
else
return "redirect:login";
}
//添加供应商界面
@RequestMapping("/providerAdd")
public String providerAdd() {
return "providerAdd";
}
@RequestMapping("/getProviders")
public String getProviderList(String proName,Model md,String pageIndex) {
String strName="";
if(!StringUtils.isEmpty(proName)) {
strName=proName;
}
Integer currentPageNo=1;
Integer pageSize=Constants.pageSize;
if(!StringUtils.isEmpty(pageIndex)) {
currentPageNo=Integer.parseInt(pageIndex);
}
//根据条件获取总记录数
Integer totalCount=proService.getProviderCount(strName);
//计算可以分几页
PageHelper pages=new PageHelper();
pages.setCurrentPageNo(currentPageNo);
pages.setPageSize(pageSize);
pages.setTotalCount(totalCount);
int totalPageCount = pages.getTotalPageCount();
List<Provider> providers=proService.getProviderList(strName,(currentPageNo-1)*pageSize,pageSize);
md.addAttribute("totalPageCount", totalPageCount);
md.addAttribute("totalCount", totalCount);
md.addAttribute("currentPageNo", currentPageNo);
md.addAttribute("providers",providers);
return "providerList";
}