• Java项目:ssm超市订单管理


    作者主页:夜未央5788

     简介:Java领域优质创作者、Java项目、学习资料、技术互助

    文末获取源码

    项目介绍

    该超市订单管理毕业设计基于jdk8版本开发,在部署时需要使用jdk8以上的版本。使用了目前流行的框架组合spring+springMVC+mybatis的框架技术, 实现了供应商管理对供应商实现增删改查、订单管理对超市订单实现增删改查、用户管理等功能,适用于小型超市的使用,通过学习该超市订单管理 的毕业设计,对于SSM框架的组合能够有更深层次的理解。

    环境需要

    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. 后端:Spring SpringMVC MyBatis
    2. 前端:JSP+jQuery

    使用说明

    1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
    2. 将项目中applicationContext.xml配置文件中的数据库配置改为自己的配置;

    3. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;

    若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行;

    4. 运行成功后,访问http://localhost:8080/supermarket/login.htm到登录页面

    运行截图

     

     

     

     

     

     

    相关代码 

    BillController

    1. package com.bjpowernode.controller;
    2. import java.util.ArrayList;
    3. import java.util.Date;
    4. import java.util.HashMap;
    5. import java.util.List;
    6. import java.util.Map;
    7. import javax.servlet.http.HttpSession;
    8. import org.springframework.beans.factory.annotation.Autowired;
    9. import org.springframework.beans.factory.annotation.Qualifier;
    10. import org.springframework.stereotype.Controller;
    11. import org.springframework.ui.Model;
    12. import org.springframework.web.bind.annotation.RequestMapping;
    13. import org.springframework.web.bind.annotation.ResponseBody;
    14. import com.alibaba.fastjson.JSONArray;
    15. import com.bjpowernode.bizImpl.SmbmsBillBizImpl;
    16. import com.bjpowernode.bizImpl.SmbmsProviderBizImpl;
    17. import com.bjpowernode.entity.SmbmsBill;
    18. import com.bjpowernode.entity.SmbmsBillExample;
    19. import com.bjpowernode.entity.SmbmsProvider;
    20. import com.bjpowernode.entity.SmbmsUser;
    21. @Controller
    22. public class BillController {
    23. @Autowired
    24. @Qualifier("bBiz")
    25. private SmbmsBillBizImpl bBiz;
    26. @Autowired
    27. @Qualifier("pBiz")
    28. private SmbmsProviderBizImpl pBiz;
    29. public void setpBiz(SmbmsProviderBizImpl pBiz) {
    30. this.pBiz = pBiz;
    31. }
    32. public void setbBiz(SmbmsBillBizImpl bBiz) {
    33. this.bBiz = bBiz;
    34. }
    35. /*进入billlist页面 modify页面 view页面*/
    36. @RequestMapping("/bill.do")
    37. public String tobilllist(Model model,String method,String billid,String queryProductName,String queryProviderId,String queryIsPayment,String pageIndex){
    38. if("view".equals(method)){
    39. SmbmsBill bill=bBiz.selectByPrimaryKey(Long.parseLong(billid));
    40. bill.setProvidername(pBiz.selectByPrimaryKey(bill.getProviderid()).getProname());/*根据供应商id,获得供应商名字*/
    41. model.addAttribute("bill", bill);
    42. return "billview";
    43. }else if("modify".equals(method)){
    44. model.addAttribute("bill", bBiz.selectByPrimaryKey(Long.parseLong(billid)));
    45. return "billmodify";
    46. }else{
    47. Map map=bBiz.selectByExample(null,queryProductName,queryProviderId,queryIsPayment,pageIndex);/*按照分页获取list 、和分页信息param*/
    48. Map map2=pBiz.selectByExample(null, null, null, null);/*获取供应商列表*/
    49. List list2=new ArrayList<>();
    50. for (SmbmsBill bill : (List)map.get("listuser")) {
    51. bill.setProvidername(pBiz.selectByPrimaryKey(bill.getProviderid()).getProname());/*根据供应商id,获得供应商名字*/
    52. list2.add(bill);
    53. }
    54. model.addAttribute("billList", list2);
    55. model.addAttribute("providerList", map2.get("listuser"));
    56. model.addAttribute("page", map.get("param"));
    57. model.addAttribute("queryProductName",queryProductName);
    58. model.addAttribute("queryProviderId", queryProviderId);
    59. model.addAttribute("queryIsPayment", queryIsPayment);
    60. return "billlist";
    61. }
    62. }
    63. /*删除bill页面 获取供应商列表*/
    64. @ResponseBody
    65. @RequestMapping("/delbill.do")
    66. public Object delbill(String billid,String method){
    67. Map map=new HashMap<>();
    68. if("delbill".equals(method)){
    69. if(bBiz.selectByPrimaryKey(Long.parseLong(billid))==null){
    70. map.put("delResult", "notexist");
    71. }
    72. int flag=bBiz.deleteByPrimaryKey(Long.parseLong(billid));
    73. if(flag>0){
    74. map.put("delResult", "true");
    75. }else{
    76. map.put("delResult", "false");
    77. }
    78. }else if("getproviderlist".equals(method)){
    79. Map map2=pBiz.selectByExample(null,null,null,null);
    80. map.put("list", map2.get("listuser"));
    81. }
    82. return JSONArray.toJSONString(map);
    83. }
    84. /*跳到添加bill页面*/
    85. @RequestMapping("/billadd.do")
    86. public String billadd(){
    87. return "billadd";
    88. }
    89. /*bill 各种save*/
    90. @RequestMapping("/billsave.do")
    91. public String billsave(String method,SmbmsBill bill,HttpSession session){
    92. if("add".equals(method)){
    93. SmbmsUser user=(SmbmsUser)session.getAttribute("userSession");
    94. bill.setCreatedby(user.getId());
    95. bill.setCreationdate(new Date());
    96. int flag=bBiz.insertSelective(bill);
    97. if(flag>0){
    98. return "redirect:/bill.do";
    99. }else{
    100. return "redirect:/billadd.do";
    101. }
    102. }else{
    103. SmbmsBillExample example=new SmbmsBillExample();
    104. SmbmsBillExample.Criteria criteria=example.createCriteria();
    105. int flag=bBiz.updateByExampleSelective(bill, example);
    106. if(flag>0){
    107. return "redirect:/bill.do";
    108. }else{
    109. return "redirect:/bill.do?method=modify&billid="+bill.getId();
    110. }
    111. }
    112. }
    113. }

    ProviderController

    1. package com.bjpowernode.controller;
    2. import java.util.HashMap;
    3. import java.util.List;
    4. import java.util.Map;
    5. import org.springframework.beans.factory.annotation.Autowired;
    6. import org.springframework.beans.factory.annotation.Qualifier;
    7. import org.springframework.stereotype.Controller;
    8. import org.springframework.ui.Model;
    9. import org.springframework.web.bind.annotation.RequestMapping;
    10. import org.springframework.web.bind.annotation.ResponseBody;
    11. import org.springframework.web.filter.DelegatingFilterProxy;
    12. import com.alibaba.fastjson.JSONArray;
    13. import com.bjpowernode.bizImpl.SmbmsProviderBizImpl;
    14. import com.bjpowernode.entity.SmbmsProvider;
    15. @Controller
    16. public class ProviderController {
    17. @Autowired
    18. @Qualifier("pBiz")
    19. private SmbmsProviderBizImpl pBiz;
    20. public void setpBiz(SmbmsProviderBizImpl pBiz) {
    21. this.pBiz = pBiz;
    22. }
    23. /*进入供应商list*/
    24. @RequestMapping("/provider.do")
    25. public String topro(Model model,String queryProCode,String queryProName,String pageIndex){
    26. Map map=pBiz.selectByExample(null,queryProCode,queryProName,pageIndex);
    27. model.addAttribute("providerList", map.get("listuser"));
    28. model.addAttribute("page", map.get("param"));
    29. model.addAttribute("queryProCode",queryProCode);
    30. model.addAttribute("queryProName", queryProName);
    31. return "providerlist";
    32. }
    33. /*根据method跳转到不同字段*/
    34. @RequestMapping("/providerALL.do")
    35. public String bymethod(String method,String proid,Model model){
    36. /*转到查看页面*/
    37. if("view".equals(method)){
    38. SmbmsProvider provider=pBiz.selectByPrimaryKey(Long.parseLong(proid));
    39. model.addAttribute("provider", provider);
    40. return "providerview";
    41. }
    42. /*转到更新页面*/
    43. else if("modify".equals(method)){
    44. SmbmsProvider provider=pBiz.selectByPrimaryKey(Long.parseLong(proid));
    45. model.addAttribute("provider", provider);
    46. return "providermodify";
    47. }
    48. /*转到添加页面*/
    49. else if("add".equals(method)){
    50. return "provideradd";
    51. }
    52. return "";
    53. }
    54. /*转到删除*/
    55. @ResponseBody
    56. @RequestMapping("/delpro")
    57. public String DelegatingFilterProxy(String proid){
    58. Map map=new HashMap<>();
    59. SmbmsProvider provider=pBiz.selectByPrimaryKey(Long.parseLong(proid));
    60. if(provider==null){
    61. map.put("delResult", "notexist");
    62. }
    63. int flag=pBiz.deleteByPrimaryKey(Long.parseLong(proid));
    64. if(flag>0){
    65. map.put("delResult", "true");
    66. }else{
    67. map.put("delResult", "false");
    68. }
    69. return JSONArray.toJSONString(map);
    70. }
    71. /*提交添加 或修改的请求*/
    72. @RequestMapping("providersave.do")
    73. public String tosave(String method,SmbmsProvider provider){
    74. if("add".equals(method)){
    75. int flag=pBiz.insertSelective(provider);
    76. if(flag>0){
    77. return "redirect:/provider.do";
    78. }else{
    79. return "provideradd";
    80. }
    81. }
    82. else{
    83. int flag=pBiz.updateByPrimaryKeySelective(provider);
    84. if(flag>0){
    85. return "redirect:/provider.do";
    86. }else{
    87. return "providermodify";
    88. }
    89. }
    90. }
    91. }

    UserController

    1. package com.bjpowernode.controller;
    2. import java.io.File;
    3. import java.text.DateFormat;
    4. import java.text.SimpleDateFormat;
    5. import java.util.*;
    6. import javax.servlet.http.HttpServletRequest;
    7. import javax.servlet.http.HttpSession;
    8. import org.apache.commons.io.FilenameUtils;
    9. import org.apache.commons.lang.math.RandomUtils;
    10. import org.apache.log4j.Logger;
    11. import org.springframework.beans.factory.annotation.Autowired;
    12. import org.springframework.beans.factory.annotation.Qualifier;
    13. import org.springframework.beans.propertyeditors.CustomDateEditor;
    14. import org.springframework.stereotype.Controller;
    15. import org.springframework.ui.Model;
    16. import org.springframework.web.bind.WebDataBinder;
    17. import org.springframework.web.bind.annotation.*;
    18. import org.springframework.web.context.request.WebRequest;
    19. import org.springframework.web.multipart.MultipartFile;
    20. import com.alibaba.fastjson.JSONArray;
    21. import com.alibaba.fastjson.annotation.JSONField;
    22. import com.bjpowernode.biz.SmbmsRoleBiz;
    23. import com.bjpowernode.biz.SmbmsUserBiz;
    24. import com.bjpowernode.entity.Param;
    25. import com.bjpowernode.entity.SmbmsRole;
    26. import com.bjpowernode.entity.SmbmsUser;
    27. @Controller
    28. public class UserController {
    29. private Logger logger=Logger.getLogger(UserController.class);
    30. @Autowired
    31. @Qualifier("uBiz")
    32. private SmbmsUserBiz uBiz;
    33. @Autowired
    34. @Qualifier("rBiz")
    35. private SmbmsRoleBiz rBiz;
    36. public void setrBiz(SmbmsRoleBiz rBiz) {
    37. this.rBiz = rBiz;
    38. }
    39. public void setuBiz(SmbmsUserBiz uBiz) {
    40. this.uBiz = uBiz;
    41. }
    42. /*登陆判断*/
    43. @RequestMapping("/login.do")
    44. public String login(SmbmsUser user,HttpSession session){
    45. Map map2=uBiz.selectByExample(user,null,null,null,null);
    46. List list=(List)map2.get("listuser");
    47. if(list.size()>0){
    48. session.setAttribute("userSession", list.get(0));
    49. return "frame";
    50. }else{
    51. return "redirect:login.htm";
    52. }
    53. }
    54. /*转到登陆页面*/
    55. @RequestMapping("/login.htm")
    56. public String tologin(){
    57. return "login";
    58. }
    59. /*进入list前先查找数据*/
    60. @RequestMapping(value="/tolist.do")
    61. public String list(Model model,String queryname,String queryUserRole,String pageIndex){
    62. List list=rBiz.selectByExample(null);/*获取角色列表*/
    63. Map map=uBiz.selectByExample(null,null,queryname,queryUserRole,pageIndex);/*按条件获取list*/
    64. model.addAttribute("roleList", list);
    65. List listuser=(List)map.get("listuser");
    66. model.addAttribute("userList", listuser);
    67. Param param=(Param)map.get("param");
    68. model.addAttribute("page", param);
    69. model.addAttribute("queryname",queryname);
    70. model.addAttribute("queryUserRole", queryUserRole);
    71. return "userlist";
    72. }
    73. /*跳到添加用户页面*/
    74. @RequestMapping("/useradd.do")
    75. public String adduser(){
    76. return "useradd";
    77. }
    78. /*Ajax查询方法*/
    79. /*第一种解决乱码方式
    80. * @RequestMapping(value="/isuser",produces={"application/json;charset=UTF-8"})*/
    81. @ResponseBody
    82. @JSONField(format="yyyy-MM-dd")
    83. @RequestMapping("/isuser")
    84. public Object isuser(String method,String usercode,String uid,String oldpassword,HttpSession session){
    85. Map map=new HashMap<>();
    86. List listMap=new ArrayList<>();
    87. /*获取角色列表*/
    88. if("getrolelist".equals(method)){
    89. List list=rBiz.selectByExample(null);
    90. for (SmbmsRole smbmsRole : list) {
    91. Map map2=new HashMap<>();
    92. map2.put("id", smbmsRole.getId());
    93. map2.put("rolename", smbmsRole.getRolename());
    94. listMap.add(map2);
    95. }
    96. map.put("rows", listMap);
    97. }
    98. /*判断code是否存在*/
    99. else if("ucexist".equals(method)){
    100. if(""==usercode){
    101. map.put("usercode", "kong");
    102. }else{
    103. Map map2=uBiz.selectByExample(null, usercode,null,null,null);
    104. List list=(List)map2.get("listuser");
    105. if(list.size()>0){
    106. map.put("usercode", "exist");
    107. }else{
    108. map.put("usercode", "true");
    109. }
    110. }
    111. }
    112. /*删除账号*/
    113. else if("deluser".equals(method)){
    114. if(uid==null){
    115. map.put("delResult", "notexist");
    116. }else{
    117. Integer flag=uBiz.deleteByPrimaryKey(Long.parseLong(uid));
    118. if(flag>0){
    119. map.put("delResult", "true");
    120. }else{
    121. map.put("delResult", "false");
    122. }
    123. }
    124. }
    125. /*判断密码是否正确*/
    126. else if("pwdmodify".equals(method)){
    127. SmbmsUser user=(SmbmsUser)session.getAttribute("userSession");
    128. if(user==null){
    129. map.put("result", "sessionerror");
    130. }
    131. if("".equals(oldpassword)){
    132. map.put("result", "error");
    133. }else{
    134. if(oldpassword.equals(user.getUserpassword())){
    135. map.put("result", "true");
    136. }else{
    137. map.put("result", "false");
    138. }
    139. }
    140. }
    141. return JSONArray.toJSONString(map);
    142. }
    143. /*添加用户,多文件上传*/
    144. @RequestMapping(value="/usersave.do",method=RequestMethod.POST)
    145. public String usersave(SmbmsUser user,HttpSession session,HttpServletRequest request,
    146. @RequestParam(value ="attachs", required = false) MultipartFile[] pics){
    147. String idPicPath = null;
    148. String workPicPath = null;
    149. String errorInfo = null;
    150. boolean flag = true;
    151. String path = request.getSession().getServletContext().getRealPath("statics"+File.separator+"uploadfiles");
    152. logger.info("uploadFile path ============== > "+path);
    153. for(int i = 0;i < pics.length ;i++){
    154. MultipartFile pic = pics[i];
    155. if(!pic.isEmpty()){
    156. if(i == 0){
    157. errorInfo = "uploadFileError";
    158. }else if(i == 1){
    159. errorInfo = "uploadWpError";
    160. }
    161. String oldFileName = pic.getOriginalFilename();//原文件名
    162. logger.info("uploadFile oldFileName ============== > "+oldFileName);
    163. String prefix=FilenameUtils.getExtension(oldFileName);//原文件后缀
    164. logger.debug("uploadFile prefix============> " + prefix);
    165. int filesize = 500000;
    166. logger.debug("uploadFile size============> " + pic.getSize());
    167. if(pic.getSize() > filesize){//上传大小不得超过 500k
    168. request.setAttribute(errorInfo, " * 上传大小不得超过 500k");
    169. flag = false;
    170. }else if(prefix.equalsIgnoreCase("jpg") || prefix.equalsIgnoreCase("png")
    171. || prefix.equalsIgnoreCase("jpeg") || prefix.equalsIgnoreCase("pneg")){//上传图片格式不正确
    172. //定义上传文件名:当前系统时间+随机数+“_Personal.jpg”
    173. String fileName = System.currentTimeMillis()+RandomUtils.nextInt(1000000)+"_Personal.jpg";
    174. logger.debug("new fileName======== " + pic.getName());
    175. File targetFile = new File(path, fileName);
    176. if(!targetFile.exists()){
    177. targetFile.mkdirs();
    178. }
    179. //保存
    180. try {
    181. pic.transferTo(targetFile);
    182. } catch (Exception e) {
    183. e.printStackTrace();
    184. request.setAttribute(errorInfo, " * 上传失败!");
    185. flag = false;
    186. }
    187. if(i == 0){
    188. idPicPath = path+File.separator+fileName;
    189. }else if(i == 1){
    190. workPicPath = path+File.separator+fileName;
    191. }
    192. logger.debug("idPicPath: " + idPicPath);
    193. logger.debug("workPicPath: " + workPicPath);
    194. }else{
    195. request.setAttribute(errorInfo, " * 上传图片格式不正确");
    196. flag = false;
    197. }
    198. }
    199. }
    200. if(flag){
    201. user.setCreatedby(((SmbmsUser)session.getAttribute("userSession")).getId());
    202. user.setCreationdate(new Date());
    203. user.setIdpicpath(idPicPath);
    204. user.setWorkpicpath(workPicPath);
    205. if(uBiz.insertSelective(user)>0){
    206. return "redirect:/tolist.do";
    207. }
    208. }
    209. return "useradd";
    210. }
    211. @InitBinder
    212. public void initBinder(WebDataBinder binder, WebRequest request) {
    213. //转换日期 注意这里的转化要和传进来的字符串的格式一直 如2015-9-9 就应该为yyyy-MM-dd
    214. DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
    215. binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));// CustomDateEditor为自定义日期编辑器
    216. }
    217. /*进入查看个人信息页面*/
    218. @RequestMapping(value="/view")
    219. public String view(String id,Model model){
    220. model.addAttribute("user", uBiz.selectByPrimaryKey(Long.parseLong(id)));
    221. return "userview";
    222. }
    223. /*进入修改个人信息页面*/
    224. @RequestMapping(value="/modify")
    225. public String modify(String id,Model model){
    226. model.addAttribute("user", uBiz.selectByPrimaryKey(Long.parseLong(id)));
    227. return "usermodify";
    228. }
    229. /*修改信息提交,成功则跳到list*/
    230. @RequestMapping("/modifysave.do")
    231. public String modifysave(SmbmsUser user){
    232. int flag=uBiz.updateByPrimaryKeySelective(user);
    233. if(flag>0){
    234. return "redirect:/tolist.do";
    235. }else{
    236. return "usermodify";
    237. }
    238. }
    239. /*进入密码修改页面*/
    240. @RequestMapping("/pwdmodify.do")
    241. public String pwdmodify(HttpSession session,Model model){
    242. Long id=((SmbmsUser)session.getAttribute("userSession")).getId();
    243. if(id==null){
    244. return "login";
    245. }
    246. model.addAttribute("user", uBiz.selectByPrimaryKey(id));
    247. return "pwdmodify";
    248. }
    249. /*提交密码修改,成功则跳到登陆页面*/
    250. @RequestMapping("/pwdmodifysave.do")
    251. public String pwdmodifysave(String newpassword,HttpSession session){
    252. SmbmsUser user=(SmbmsUser)session.getAttribute("userSession");
    253. user.setUserpassword(newpassword);
    254. int flag=uBiz.updateByPrimaryKeySelective(user);
    255. if(flag>0){
    256. return "redirect:logout.do";
    257. }else{
    258. return "pwdmodify.do";
    259. }
    260. }
    261. /*注销*/
    262. @RequestMapping("/logout.do")
    263. public String loginout(HttpSession session){
    264. session.removeAttribute("userSession");
    265. return "syserror";
    266. }
    267. }

    如果也想学习本系统,下面领取。关注并回复:023ssm 

  • 相关阅读:
    python爬虫模板和网页表格生成表格文件
    [附源码]Python计算机毕业设计SSM康健医药公司进销存管理系统(程序+LW)
    k8s 安装 rocketmq 集群
    继电器的故障处理
    [附源码]java毕业设计火车票预订系统论文2022
    阿里巴巴1688/京东/淘宝天猫API接口
    可编程直流回馈式负载箱的工作原理
    Nginx快速入门
    初识Pytest自动化测试框架,我彻底懂了
    【Seata】分布式事务框架原理解析
  • 原文地址:https://blog.csdn.net/hanyunlong1989/article/details/126789641