当前位置:   article > 正文

java项目-基于SSM实现物流信息管理系统_基于ssm框架的项目

基于ssm框架的项目

作者主页:编程指南针

作者简介:Java领域优质创作者、CSDN博客专家 、掘金特邀作者、多年架构师设计经验、腾讯课堂常驻讲师

主要内容:Java项目、毕业设计、简历模板、学习资料、面试题库、技术互助

文末获取源码 

项目编号:BS-XX-118

一,项目简介

基于SSM框架的物流管理系统主要分为三种用户角色,分别是管理员、员工以及客户用户,其具体功能如下:

管理员:管理员登录后主要功能模块有个人信息,客户管理,反馈信息,基础信息,货物信息以及货物运输。

员工用户:员工用户登录后主要模块有个人信息,配送范围,货物信息,货物运输以及反馈信息。

客户用户:客户用户登录后主要模块有个人信息,配送范围,货物信息,货物运输以及反馈信息。

二,环境介绍

语言环境:Java:  jdk1.8

数据库:Mysql: mysql5.7

应用服务器:Tomcat:  tomcat8.5.31

开发工具:IDEA或eclipse

后台开发:SSM框架

前端开发:Bootstrap+Jquery+Echart

三,系统展示

展示一下部分系统的功能:

用户登陆

管理员主功能界面:

员工管理

客户管理

反馈信息

基础信息管理

货物信息审核

货物运输

客户角色的管理主界面

普通管理用户的管理主界面

四,核心代码展示

  1. package com.action;
  2. import java.util.Date;
  3. import java.util.List;
  4. import javax.servlet.http.HttpServletRequest;
  5. import javax.servlet.http.HttpServletResponse;
  6. import net.sf.json.JSONArray;
  7. import net.sf.json.JSONObject;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Controller;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.multipart.MultipartFile;
  12. import com.model.*;
  13. import com.service.*;
  14. import com.util.*;
  15. @Controller
  16. public class GgtypeAction {
  17. @Autowired
  18. private GgtypeService ggtypeService;
  19. @RequestMapping("/getGgtypes")
  20. public void getGgtypes(HttpServletRequest request,
  21. HttpServletResponse response) throws Exception {
  22. request.setCharacterEncoding("UTF-8");
  23. response.setCharacterEncoding("UTF-8");
  24. String page = (String) request.getParameter("page");
  25. String rows = (String) request.getParameter("rows");
  26. String ggtypeName = (String) request.getParameter("ggtypeName");
  27. String ggtypeId = (String) request.getParameter("ggtypeId");
  28. PageBean pageBean = new PageBean(Integer.parseInt(page), Integer.parseInt(rows));
  29. Ggtype ggtype = new Ggtype();
  30. try {
  31. if (StringUtil.isNotEmpty(ggtypeName)) {
  32. ggtype.setGgtypeName(ggtypeName);
  33. }
  34. if (StringUtil.isNotEmpty(ggtypeId)) {
  35. ggtype.setGgtypeId(Integer.parseInt(ggtypeId));
  36. }
  37. JSONArray jsonArray = JSONArray.fromObject(ggtypeService.queryGgtypes(ggtype, pageBean.getStart(), pageBean.getRows()));
  38. JSONObject result = new JSONObject();
  39. int total = ggtypeService.queryGgtypes(ggtype, 0, 0).size();
  40. result.put("rows", jsonArray);
  41. result.put("total", total);
  42. ResponseUtil.write(response, result);
  43. } catch (Exception e) {
  44. e.printStackTrace();
  45. }
  46. }
  47. @RequestMapping("/addGgtype")
  48. public void addGgtype(HttpServletRequest request, HttpServletResponse response)
  49. throws Exception {
  50. request.setCharacterEncoding("UTF-8");
  51. response.setCharacterEncoding("UTF-8");
  52. try {
  53. JSONObject result = new JSONObject();
  54. String ggtypeName = (String) request.getParameter("ggtypeName");
  55. String ggtypeMark = (String) request.getParameter("ggtypeMark");
  56. String ggtypeId = (String) request.getParameter("ggtypeId");
  57. Ggtype ggtype = new Ggtype();
  58. if (StringUtil.isNotEmpty(ggtypeId)) {
  59. ggtype = ggtypeService.getGgtype(Integer.parseInt(ggtypeId));
  60. }
  61. if (StringUtil.isNotEmpty(ggtypeName)) {
  62. ggtype.setGgtypeName(ggtypeName);
  63. }
  64. if (StringUtil.isNotEmpty(ggtypeMark)) {
  65. ggtype.setGgtypeMark(ggtypeMark);
  66. }
  67. if (StringUtil.isNotEmpty(ggtypeId)) {
  68. ggtypeService.modifyGgtype(ggtype);
  69. } else {
  70. ggtypeService.save(ggtype);
  71. }
  72. result.put("success", "true");
  73. ResponseUtil.write(response, result);
  74. } catch (Exception e) {
  75. e.printStackTrace();
  76. }
  77. }
  78. @RequestMapping("/deleteGgtype")
  79. public void deleteGgtype(HttpServletRequest request, HttpServletResponse response)
  80. throws Exception {
  81. try {
  82. String delIds = (String) request.getParameter("delIds");
  83. System.out.println("delIds = " + delIds);
  84. JSONObject result = new JSONObject();
  85. String str[] = delIds.split(",");
  86. for (int i = 0; i < str.length; i++) {
  87. ggtypeService.deleteGgtype(Integer.parseInt(str[i]));
  88. }
  89. result.put("success", "true");
  90. result.put("delNums", str.length);
  91. ResponseUtil.write(response, result);
  92. } catch (Exception e) {
  93. e.printStackTrace();
  94. }
  95. }
  96. @RequestMapping("/ggtypeComboList")
  97. public void ggtypeComboList(HttpServletRequest request, HttpServletResponse response)
  98. throws Exception {
  99. try {
  100. JSONArray jsonArray = new JSONArray();
  101. JSONObject jsonObject = new JSONObject();
  102. jsonObject.put("id", "");
  103. jsonObject.put("ggtypeName", "请选择...");
  104. jsonArray.add(jsonObject);
  105. jsonArray.addAll(JSONArray.fromObject(ggtypeService.queryGgtypes(null, 0, 0)));
  106. ResponseUtil.write(response, jsonArray);
  107. } catch (Exception e) {
  108. e.printStackTrace();
  109. }
  110. }
  111. }
  1. package com.action;
  2. import javax.servlet.http.HttpServletRequest;
  3. import javax.servlet.http.HttpServletResponse;
  4. import net.sf.json.JSONObject;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Controller;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import com.model.*;
  9. import com.service.*;
  10. @Controller
  11. public class AdminAction {
  12. @Autowired
  13. private AdminService adminService;
  14. @RequestMapping("/mimaAdmin")
  15. public void mimaAdmin(HttpServletRequest request, HttpServletResponse response)
  16. throws Exception {
  17. try {
  18. JSONObject result = new JSONObject();
  19. String adminPassword = (String) request.getParameter("adminPassword");
  20. String adminPassword1 = (String) request.getParameter("adminPassword1");
  21. Admin admin = new Admin();
  22. admin.setAdminName("admin");
  23. admin.setAdminPassword(adminPassword);
  24. if (adminService.queryAdmins(admin, 0, 0).size()==1) {
  25. admin = (Admin)(adminService.queryAdmins(admin, 0, 0)).get(0);
  26. admin.setAdminPassword(adminPassword1);
  27. adminService.modifyAdmin(admin);
  28. request.setAttribute("error", "密码修改成功!");
  29. request.getRequestDispatcher("adminmima.jsp").forward(request,
  30. response);
  31. }else{
  32. result.put("success", "true");
  33. request.setAttribute("error", "原密码错误,请重新输入!");
  34. request.getRequestDispatcher("adminmima.jsp").forward(request,
  35. response);
  36. }
  37. } catch (Exception e) {
  38. e.printStackTrace();
  39. }
  40. }
  41. }

  1. package com.action;
  2. import java.util.Date;
  3. import java.util.List;
  4. import javax.servlet.http.HttpServletRequest;
  5. import javax.servlet.http.HttpServletResponse;
  6. import net.sf.json.JSONArray;
  7. import net.sf.json.JSONObject;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Controller;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.multipart.MultipartFile;
  12. import com.model.*;
  13. import com.service.*;
  14. import com.util.*;
  15. @Controller
  16. public class RoleAction {
  17. @Autowired
  18. private RoleService roleService;
  19. @RequestMapping("/getRoles")
  20. public void getRoles(HttpServletRequest request,
  21. HttpServletResponse response) throws Exception {
  22. request.setCharacterEncoding("UTF-8");
  23. response.setCharacterEncoding("UTF-8");
  24. String page = (String) request.getParameter("page");
  25. String rows = (String) request.getParameter("rows");
  26. String roleName = (String) request.getParameter("roleName");
  27. String roleId = (String) request.getParameter("roleId");
  28. String roleMark2 = (String) request.getParameter("roleMark2");
  29. PageBean pageBean = new PageBean(Integer.parseInt(page), Integer.parseInt(rows));
  30. Role role = new Role();
  31. try {
  32. if (StringUtil.isNotEmpty(roleName)) {
  33. role.setRoleName(roleName);
  34. }
  35. if (StringUtil.isNotEmpty(roleId)) {
  36. role.setRoleId(Integer.parseInt(roleId));
  37. }
  38. if (StringUtil.isNotEmpty(roleMark2)) {
  39. role.setRoleMark2(Integer.parseInt(roleMark2));
  40. }
  41. JSONArray jsonArray = JSONArray.fromObject(roleService.queryRoles(role, pageBean.getStart(), pageBean.getRows()));
  42. JSONObject result = new JSONObject();
  43. int total = roleService.queryRoles(role, 0, 0).size();
  44. result.put("rows", jsonArray);
  45. result.put("total", total);
  46. ResponseUtil.write(response, result);
  47. } catch (Exception e) {
  48. e.printStackTrace();
  49. }
  50. }
  51. @RequestMapping("/addRole")
  52. public void addRole(HttpServletRequest request, HttpServletResponse response)
  53. throws Exception {
  54. request.setCharacterEncoding("UTF-8");
  55. response.setCharacterEncoding("UTF-8");
  56. try {
  57. JSONObject result = new JSONObject();
  58. String roleName = (String) request.getParameter("roleName");
  59. String roleMark = (String) request.getParameter("roleMark");
  60. String roleMark1 = (String) request.getParameter("roleMark1");
  61. String roleMark2 = (String) request.getParameter("roleMark2");
  62. String roleId = (String) request.getParameter("roleId");
  63. Role role = new Role();
  64. if (StringUtil.isNotEmpty(roleId)) {
  65. role = roleService.getRole(Integer.parseInt(roleId));
  66. }
  67. if (StringUtil.isNotEmpty(roleName)) {
  68. role.setRoleName(roleName);
  69. }
  70. if (StringUtil.isNotEmpty(roleMark)) {
  71. role.setRoleMark(roleMark);
  72. }
  73. if (StringUtil.isNotEmpty(roleMark1)) {
  74. role.setRoleMark1(roleMark1);
  75. }
  76. if (StringUtil.isNotEmpty(roleMark2)) {
  77. role.setRoleMark2(Integer.parseInt(roleMark2));
  78. }
  79. if (StringUtil.isNotEmpty(roleId)) {
  80. roleService.modifyRole(role);
  81. } else {
  82. roleService.save(role);
  83. }
  84. result.put("success", "true");
  85. ResponseUtil.write(response, result);
  86. } catch (Exception e) {
  87. e.printStackTrace();
  88. }
  89. }
  90. @RequestMapping("/deleteRole")
  91. public void deleteRole(HttpServletRequest request, HttpServletResponse response)
  92. throws Exception {
  93. try {
  94. String delIds = (String) request.getParameter("delIds");
  95. System.out.println("delIds = " + delIds);
  96. JSONObject result = new JSONObject();
  97. String str[] = delIds.split(",");
  98. for (int i = 0; i < str.length; i++) {
  99. roleService.deleteRole(Integer.parseInt(str[i]));
  100. }
  101. result.put("success", "true");
  102. result.put("delNums", str.length);
  103. ResponseUtil.write(response, result);
  104. } catch (Exception e) {
  105. e.printStackTrace();
  106. }
  107. }
  108. @RequestMapping("/roleComboList")
  109. public void roleComboList(HttpServletRequest request, HttpServletResponse response)
  110. throws Exception {
  111. request.setCharacterEncoding("UTF-8");
  112. response.setCharacterEncoding("UTF-8");
  113. String roleMark2 = (String) request.getParameter("roleMark2");
  114. Role role = new Role();
  115. if (StringUtil.isNotEmpty(roleMark2)) {
  116. role.setRoleMark2(Integer.parseInt(roleMark2));
  117. }
  118. try {
  119. JSONArray jsonArray = new JSONArray();
  120. JSONObject jsonObject = new JSONObject();
  121. jsonObject.put("id", "");
  122. jsonObject.put("roleName", "请选择...");
  123. jsonArray.add(jsonObject);
  124. //jsonArray.addAll(JSONArray.fromObject(roleService.queryRoles(role, 0, 0)));
  125. ResponseUtil.write(response, jsonArray);
  126. } catch (Exception e) {
  127. e.printStackTrace();
  128. }
  129. }
  130. }
  1. package com.action;
  2. import java.util.ArrayList;
  3. import java.util.Date;
  4. import java.util.List;
  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.servlet.http.HttpServletResponse;
  7. import javax.servlet.http.HttpSession;
  8. import net.sf.json.JSONArray;
  9. import net.sf.json.JSONObject;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Controller;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.multipart.MultipartFile;
  14. import com.model.*;
  15. import com.service.*;
  16. import com.util.*;
  17. import java.io.BufferedInputStream;
  18. import java.io.BufferedOutputStream;
  19. import java.io.File;
  20. import java.io.FileInputStream;
  21. import java.io.FileOutputStream;
  22. import java.io.InputStream;
  23. import java.io.OutputStream;
  24. import java.net.URLEncoder;
  25. //导入导出
  26. import org.apache.poi.hssf.usermodel.HSSFCell;
  27. import org.apache.poi.hssf.usermodel.HSSFCellStyle;
  28. import org.apache.poi.hssf.usermodel.HSSFRow;
  29. import org.apache.poi.hssf.usermodel.HSSFSheet;
  30. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  31. import org.apache.poi.ss.usermodel.Cell;
  32. import org.apache.poi.ss.usermodel.Row;
  33. import org.apache.poi.ss.usermodel.Sheet;
  34. import org.apache.poi.ss.usermodel.Workbook;
  35. @Controller
  36. public class GonggaoAction {
  37. @Autowired
  38. private GonggaoService gonggaoService;
  39. @Autowired
  40. private GgtypeService ggtypeService;
  41. /***上传导入开始***/
  42. private InputStream excelFile;
  43. public InputStream getExcelFile() {
  44. return excelFile;
  45. }
  46. /***上传导入结束***/
  47. @RequestMapping("/getGonggaos")
  48. public void getGonggaos(HttpServletRequest request,
  49. HttpServletResponse response) throws Exception {
  50. request.setCharacterEncoding("UTF-8");
  51. response.setCharacterEncoding("UTF-8");
  52. String page = (String) request.getParameter("page");
  53. String rows = (String) request.getParameter("rows");
  54. String gonggaoName = (String) request.getParameter("gonggaoName");
  55. String gonggaoId = (String) request.getParameter("gonggaoId");
  56. String ggtypeId = (String) request.getParameter("ggtypeId");
  57. String sdate = (String) request.getParameter("sdate");
  58. String edate = (String) request.getParameter("edate");
  59. PageBean pageBean = new PageBean(Integer.parseInt(page), Integer.parseInt(rows));
  60. Gonggao gonggao = new Gonggao();
  61. try {
  62. if (StringUtil.isNotEmpty(gonggaoName)) {
  63. gonggao.setGonggaoName(gonggaoName);
  64. }
  65. if (StringUtil.isNotEmpty(gonggaoId)) {
  66. gonggao.setGonggaoId(Integer.parseInt(gonggaoId));
  67. }
  68. if (StringUtil.isNotEmpty(ggtypeId)) {
  69. gonggao.setGgtypeId(Integer.parseInt(ggtypeId));
  70. }
  71. JSONArray jsonArray = JSONArray.fromObject(gonggaoService.queryGonggaos(
  72. gonggao, pageBean.getStart(), pageBean.getRows(), sdate, edate));
  73. JSONObject result = new JSONObject();
  74. int total = gonggaoService.queryGonggaos(gonggao, 0, 0, sdate, edate).size();
  75. result.put("rows", jsonArray);
  76. result.put("total", total);
  77. ResponseUtil.write(response, result);
  78. } catch (Exception e) {
  79. e.printStackTrace();
  80. }
  81. }
  82. @RequestMapping("/addGonggao")
  83. public void addGonggao(HttpServletRequest request, HttpServletResponse response)
  84. throws Exception {
  85. JSONObject result = new JSONObject();
  86. request.setCharacterEncoding("UTF-8");
  87. response.setCharacterEncoding("UTF-8");
  88. String gonggaoName = (String) request.getParameter("gonggaoName");
  89. String gonggaoMark = (String) request.getParameter("gonggaoMark");
  90. String gonggaoDate = (String) request.getParameter("gonggaoDate");
  91. String ggtypeId = (String) request.getParameter("ggtypeId");
  92. String gonggaoId = (String) request.getParameter("gonggaoId");
  93. Gonggao gonggao = new Gonggao();
  94. if (StringUtil.isNotEmpty(gonggaoId)) {
  95. gonggao = gonggaoService.getGonggao(Integer.parseInt(gonggaoId));
  96. }
  97. if (StringUtil.isNotEmpty(gonggaoName)) {
  98. gonggao.setGonggaoName(gonggaoName);
  99. }
  100. if (StringUtil.isNotEmpty(gonggaoMark)) {
  101. gonggao.setGonggaoMark(gonggaoMark);
  102. }
  103. if (StringUtil.isNotEmpty(gonggaoDate)) {
  104. gonggao.setGonggaoDate(DateUtil.formatString(gonggaoDate,
  105. "yyyy-MM-dd hh:mm:ss"));
  106. }
  107. if (StringUtil.isNotEmpty(ggtypeId)) {
  108. gonggao.setGgtypeId(Integer.parseInt(ggtypeId));
  109. Ggtype ggtype = new Ggtype();
  110. ggtype = ggtypeService.getGgtype(Integer.parseInt(ggtypeId));
  111. gonggao.setGgtypeName(ggtype.getGgtypeName());
  112. }
  113. try {
  114. if (StringUtil.isNotEmpty(gonggaoId)) {
  115. gonggaoService.modifyGonggao(gonggao);
  116. result.put("success", "true");
  117. ResponseUtil.write(response, result);
  118. } else {
  119. Date date = new Date();
  120. gonggao.setGonggaoDate(date);
  121. gonggaoService.save(gonggao);
  122. result.put("success", "true");
  123. ResponseUtil.write(response, result);
  124. }
  125. } catch (Exception e) {
  126. e.printStackTrace();
  127. }
  128. }
  129. @RequestMapping("/deleteGonggao")
  130. public void deleteGonggao(HttpServletRequest request, HttpServletResponse response)
  131. throws Exception {
  132. JSONObject result = new JSONObject();
  133. String delIds = (String) request.getParameter("delIds");
  134. try {
  135. String str[] = delIds.split(",");
  136. for (int i = 0; i < str.length; i++) {
  137. gonggaoService.deleteGonggao(Integer.parseInt(str[i]));
  138. }
  139. result.put("success", "true");
  140. result.put("delNums", str.length);
  141. ResponseUtil.write(response, result);
  142. } catch (Exception e) {
  143. e.printStackTrace();
  144. }
  145. }
  146. @RequestMapping("/gonggaoComboList")
  147. public void gonggaoComboList(HttpServletRequest request, HttpServletResponse response)
  148. throws Exception {
  149. request.setCharacterEncoding("UTF-8");
  150. response.setCharacterEncoding("UTF-8");
  151. String ggtypeId = (String) request.getParameter("ggtypeId");
  152. Gonggao gonggao = new Gonggao();
  153. if (StringUtil.isNotEmpty(ggtypeId)) {
  154. gonggao.setGgtypeId(Integer.parseInt(ggtypeId));
  155. }
  156. try {
  157. JSONArray jsonArray = new JSONArray();
  158. JSONObject jsonObject = new JSONObject();
  159. jsonObject.put("id", "");
  160. jsonObject.put("gonggaoName", "请选择...");
  161. jsonArray.add(jsonObject);
  162. jsonArray.addAll(JSONArray.fromObject(gonggaoService.queryGonggaos(gonggao, 0, 0, null, null)));
  163. ResponseUtil.write(response, jsonArray);
  164. } catch (Exception e) {
  165. e.printStackTrace();
  166. }
  167. }
  168. @RequestMapping("/gonggaoTongji")
  169. public void gonggaoTongji(HttpServletRequest request, HttpServletResponse response)
  170. throws Exception {
  171. request.setCharacterEncoding("UTF-8");
  172. response.setCharacterEncoding("UTF-8");
  173. String sdate=request.getParameter("sdate");
  174. String edate=request.getParameter("edate");
  175. List<Integer> ggtypeIds = new ArrayList<Integer>();
  176. List<String> ggtypeNames = new ArrayList<String>();
  177. List<Integer> gonggaoZongshus = new ArrayList<Integer>();
  178. List<Ggtype> ggtypes = new ArrayList<Ggtype>();
  179. List<Gonggao> gonggaos = new ArrayList<Gonggao>();
  180. Gonggao gonggao = new Gonggao();
  181. Integer zongshu = 0;
  182. try {
  183. ggtypes = ggtypeService.queryGgtypes(null, 0,0);
  184. for(int i=0;i<ggtypes.size();i++){
  185. ggtypeIds.add(ggtypes.get(i).getGgtypeId());
  186. ggtypeNames.add(ggtypes.get(i).getGgtypeName());
  187. }
  188. for(int i=0;i<ggtypeIds.size();i++){
  189. Integer gonggaoZongshu = 0;
  190. gonggao.setGgtypeId(ggtypeIds.get(i));
  191. gonggaos = gonggaoService.queryGonggaos(gonggao, 0, 0, sdate, edate);
  192. for(int j=0;j<gonggaos.size();j++){
  193. gonggaoZongshu = gonggaoZongshu + gonggaos.size();
  194. }
  195. zongshu = zongshu + gonggaoZongshu;
  196. gonggaoZongshus.add(gonggaoZongshu);
  197. }
  198. HttpSession session = request.getSession();
  199. session.setAttribute("ggtypeNames", ggtypeNames);
  200. session.setAttribute("gonggaoZongshus", gonggaoZongshus);
  201. session.setAttribute("zongshu", zongshu);
  202. response.sendRedirect("admin/gonggaotongji.jsp");
  203. } catch (Exception e) {
  204. e.printStackTrace();
  205. }
  206. }
  207. @RequestMapping("/shangchuanGonggao")
  208. public void shangchuanGonggao(HttpServletRequest request, HttpServletResponse response,MultipartFile uploadFile)
  209. throws Exception {
  210. try {
  211. String gonggaoId = (String) request.getParameter("gonggaoId");
  212. String directory = "/file";
  213. String targetDirectory = request.getSession().getServletContext().getRealPath(directory);
  214. String fileName = uploadFile.getOriginalFilename();
  215. File dir = new File(targetDirectory,fileName);
  216. if(!dir.exists()){
  217. dir.mkdirs();
  218. }
  219. //MultipartFile自带的解析方法
  220. uploadFile.transferTo(dir);
  221. String shangchuandizhi = "/file" + "/" + fileName;
  222. String shangchuanname = fileName;
  223. Gonggao gonggao = gonggaoService.getGonggao(Integer.parseInt(gonggaoId));
  224. gonggao.setGonggaoImg(shangchuandizhi);
  225. gonggao.setGonggaoImgName(shangchuanname);
  226. gonggaoService.modifyGonggao(gonggao);
  227. JSONObject result = new JSONObject();
  228. result.put("success", "true");
  229. ResponseUtil.write(response, result);
  230. } catch (Exception e) {
  231. e.printStackTrace();
  232. }
  233. }
  234. @RequestMapping("/xiazaiGonggao")
  235. public void xiazaiGonggao(HttpServletRequest request, HttpServletResponse response)
  236. throws Exception {
  237. String filename = (String) request.getParameter("filename");
  238. //模拟文件,myfile.txt为需要下载的文件
  239. String path = request.getSession().getServletContext().getRealPath("file")+"\\"+filename;
  240. //获取输入流
  241. InputStream bis = new BufferedInputStream(new FileInputStream(new File(path)));
  242. //转码,免得文件名中文乱码
  243. filename = URLEncoder.encode(filename,"UTF-8");
  244. //设置文件下载头
  245. response.addHeader("Content-Disposition", "attachment;filename=" + filename);
  246. //1.设置文件ContentType类型,这样设置,会自动判断下载文件类型
  247. response.setContentType("multipart/form-data");
  248. BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
  249. int len = 0;
  250. while((len = bis.read()) != -1){
  251. out.write(len);
  252. out.flush();
  253. }
  254. out.close();
  255. }
  256. @RequestMapping("/daoruGonggao")
  257. public void daoruGonggao(HttpServletRequest request, HttpServletResponse response,MultipartFile uploadFile)
  258. throws Exception {
  259. try {
  260. String directory = "/file";
  261. String targetDirectory = request.getSession().getServletContext().getRealPath(directory);
  262. String fileName = uploadFile.getOriginalFilename();
  263. File dir = new File(targetDirectory,fileName);
  264. if(!dir.exists()){
  265. dir.mkdirs();
  266. }
  267. //MultipartFile自带的解析方法
  268. uploadFile.transferTo(dir);
  269. excelFile = new FileInputStream(dir);
  270. Workbook wb = new HSSFWorkbook(excelFile);
  271. Sheet sheet = wb.getSheetAt(0);
  272. int rowNum = sheet.getLastRowNum() + 1;
  273. for (int i = 1; i < rowNum; i++) {
  274. Gonggao gonggao = new Gonggao();
  275. Row row = sheet.getRow(i);
  276. int cellNum = row.getLastCellNum();
  277. for (int j = 0; j < cellNum; j++) {
  278. Cell cell = row.getCell(j);
  279. String cellValue = null;
  280. switch (cell.getCellType()) { // 判断excel单元格内容的格式,并对其进行转换,以便插入数据库
  281. case 0:
  282. cellValue = String.valueOf((int) cell
  283. .getNumericCellValue());
  284. break;
  285. case 1:
  286. cellValue = cell.getStringCellValue();
  287. break;
  288. case 2:
  289. cellValue = cell.getStringCellValue();
  290. break;
  291. }
  292. switch (j) {// 通过列数来判断对应插如的字段
  293. case 1:
  294. gonggao.setGonggaoName(cellValue);
  295. break;
  296. case 2:
  297. gonggao.setGonggaoMark(cellValue);
  298. break;
  299. }
  300. }
  301. gonggaoService.save(gonggao);
  302. }
  303. JSONObject result = new JSONObject();
  304. result.put("success", "true");
  305. ResponseUtil.write(response, result);
  306. } catch (Exception e) {
  307. e.printStackTrace();
  308. }
  309. }
  310. @RequestMapping("/daochuGonggao")
  311. public void daochuGonggao(HttpServletRequest request, HttpServletResponse response)
  312. throws Exception {
  313. String delIds = (String) request.getParameter("delIds");
  314. JSONObject result = new JSONObject();
  315. String str[] = delIds.split(",");
  316. // 创建一个Excel文件
  317. HSSFWorkbook workbook = new HSSFWorkbook();
  318. // 创建一个工作表
  319. HSSFSheet sheet = workbook.createSheet("gonggaos记录");
  320. // 添加表头行
  321. HSSFRow hssfRow = sheet.createRow(0);
  322. // 设置单元格格式居中
  323. HSSFCellStyle cellStyle = workbook.createCellStyle();
  324. cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
  325. // 添加表头内容
  326. HSSFCell headCell = hssfRow.createCell(0);
  327. headCell.setCellValue("编号");
  328. headCell.setCellStyle(cellStyle);
  329. headCell = hssfRow.createCell(1);
  330. headCell.setCellValue("用户名");
  331. headCell.setCellStyle(cellStyle);
  332. headCell = hssfRow.createCell(2);
  333. headCell.setCellValue("密码");
  334. headCell.setCellStyle(cellStyle);
  335. headCell = hssfRow.createCell(3);
  336. headCell.setCellValue("姓名");
  337. headCell.setCellStyle(cellStyle);
  338. headCell = hssfRow.createCell(4);
  339. headCell.setCellValue("性别");
  340. headCell.setCellStyle(cellStyle);
  341. headCell = hssfRow.createCell(5);
  342. headCell.setCellValue("年龄");
  343. headCell.setCellStyle(cellStyle);
  344. headCell = hssfRow.createCell(6);
  345. headCell.setCellValue("电话");
  346. headCell.setCellStyle(cellStyle);
  347. headCell = hssfRow.createCell(7);
  348. headCell.setCellValue("备注1");
  349. headCell.setCellStyle(cellStyle);
  350. headCell = hssfRow.createCell(8);
  351. headCell.setCellValue("备注2");
  352. headCell.setCellStyle(cellStyle);
  353. headCell = hssfRow.createCell(9);
  354. headCell.setCellValue("备注3");
  355. headCell.setCellStyle(cellStyle);
  356. headCell = hssfRow.createCell(10);
  357. headCell.setCellValue("备注4");
  358. headCell.setCellStyle(cellStyle);
  359. headCell = hssfRow.createCell(13);
  360. headCell.setCellValue("标志1");
  361. headCell.setCellStyle(cellStyle);
  362. headCell = hssfRow.createCell(14);
  363. headCell.setCellValue("备注2");
  364. headCell.setCellStyle(cellStyle);
  365. headCell = hssfRow.createCell(15);
  366. headCell.setCellValue("权限");
  367. headCell.setCellStyle(cellStyle);
  368. headCell = hssfRow.createCell(16);
  369. headCell.setCellValue("部门");
  370. headCell.setCellStyle(cellStyle);
  371. // 添加数据内容
  372. for (int i = 0; i < str.length; i++) {
  373. hssfRow = sheet.createRow((int) i + 1);
  374. Gonggao gonggao = gonggaoService.getGonggao(Integer.parseInt(str[i]));
  375. // 创建单元格,并设置值
  376. HSSFCell cell = hssfRow.createCell(0);
  377. cell.setCellValue(gonggao.getGonggaoId());
  378. cell.setCellStyle(cellStyle);
  379. cell = hssfRow.createCell(1);
  380. cell.setCellValue(gonggao.getGonggaoName());
  381. cell.setCellStyle(cellStyle);
  382. cell = hssfRow.createCell(7);
  383. cell.setCellValue(gonggao.getGonggaoMark());
  384. cell.setCellStyle(cellStyle);
  385. cell = hssfRow.createCell(16);
  386. cell.setCellValue(gonggao.getGgtypeName());
  387. cell.setCellStyle(cellStyle);
  388. }
  389. // 保存Excel文件
  390. try {
  391. Date date = new Date();
  392. String strdate = DateUtil.formatDate(date, "yyyyMMddhhmmss");
  393. OutputStream outputStream = new FileOutputStream("D:/gonggao"
  394. + strdate + ".xls");
  395. workbook.write(outputStream);
  396. outputStream.close();
  397. result.put("success", "true");
  398. ResponseUtil.write(response, result);
  399. } catch (Exception e) {
  400. e.printStackTrace();
  401. }
  402. }
  403. }

五,项目总结

   本项目主要基于物流信息的基本管理功能实现的一个信息化管理系统,客户登陆系统后可以添加货物并进行运输信息的选择和添加,普通用户进入系统可以对用户的发货信息进行审核,并根据运输情况改变运输状态,客户在货物运达后可以进行验收操作。整个业务流程十分完整。管理员主要进行基础信息的基本管理,也可以进行相关的业务操作。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/155677
推荐阅读
相关标签
  

闽ICP备14008679号