• Java项目:基于ssh的酒窖酒水管理系统


    作者主页:夜未央5788

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

    文末获取源码

    项目介绍

    本项目为基于SSH的酒窖管理系统,可以完美运行。具有酒水管理和会员管理两大块内容。
    酒水管理包括:酒水基本信息、酒水入库管理、酒水出售管理;
    客户管理包括:客户基本信息、会员基本信息、酒水保存信息;

    环境需要

    1.运行环境:java jdk 1.7;注:本项目目前仅支持jdk 1.7;
    2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
    3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
    4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 
    5.数据库:MySql 5.7版本;

    6.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目

    技术栈

    1. 后端:Spring Struts2 Hibernate

    2. 前端:JSP+css+javascript+jQuery+easyUI+ztree

    使用说明

    1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
    2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
    若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
    3. 将项目中db.properties配置文件中的数据库配置改为自己的配置;
    4. 运行项目,在浏览器中输入http://localhost:8080/ 登录

    管理员账号密码:admin/admin

    运行截图

     

     

     

     

     

     

     

    相关代码 

    BaseAction

    1. package com.deng.web.action.base;
    2. import java.io.IOException;
    3. import java.io.UnsupportedEncodingException;
    4. import java.lang.reflect.ParameterizedType;
    5. import java.lang.reflect.Type;
    6. import java.util.List;
    7. import javax.servlet.http.HttpServletRequest;
    8. import javax.servlet.http.HttpSession;
    9. import net.sf.json.JSONArray;
    10. import net.sf.json.JSONObject;
    11. import net.sf.json.JsonConfig;
    12. import org.apache.struts2.ServletActionContext;
    13. import org.hibernate.criterion.DetachedCriteria;
    14. import com.deng.domain.PageBean;
    15. import com.deng.utils.DateJsonValueProcessor;
    16. import com.opensymphony.xwork2.ActionSupport;
    17. import com.opensymphony.xwork2.ModelDriven;
    18. public class BaseAction extends ActionSupport implements ModelDriven {
    19. private static final long serialVersionUID = 6788265612879264198L;
    20. // 定义模型对象
    21. protected T model;
    22. // 返回模型对象
    23. public T getModel() {
    24. return model;
    25. }
    26. protected PageBean pageBean = new PageBean();
    27. private int page;
    28. private int rows;
    29. public void setPage(int page) {
    30. this.page = page;
    31. }
    32. public void setRows(int rows) {
    33. this.rows = rows;
    34. }
    35. DetachedCriteria detachedCriteria = null;
    36. public BaseAction() {
    37. // 获得父类的类型(BaseAction)
    38. ParameterizedType genericSuperclass = (ParameterizedType) this
    39. .getClass().getGenericSuperclass();
    40. // 获得BaseAction上声明的泛型数组
    41. Type[] actualTypeArguments = genericSuperclass.getActualTypeArguments();
    42. // 实体类型
    43. Class entityClass = (Class) actualTypeArguments[0];
    44. detachedCriteria = DetachedCriteria.forClass(entityClass);
    45. pageBean.setDetachedCriteria(detachedCriteria);
    46. // 通过反射创建model对象
    47. try {
    48. model = entityClass.newInstance();
    49. } catch (InstantiationException e) {
    50. e.printStackTrace();
    51. } catch (IllegalAccessException e) {
    52. e.printStackTrace();
    53. }
    54. }
    55. /**
    56. * 将PageBean对象转为json数据返回
    57. *
    58. * @param pageBean
    59. * @param excludes
    60. */
    61. public void writePageBean2Json(PageBean pageBean, String[] excludes) {
    62. JsonConfig jsonConfig = new JsonConfig();
    63. jsonConfig.setExcludes(excludes);
    64. jsonConfig.setIgnoreDefaultExcludes(false);
    65. jsonConfig.registerJsonValueProcessor(java.sql.Date.class,
    66. new DateJsonValueProcessor("yyyy-MM-dd"));
    67. jsonConfig.registerJsonValueProcessor(java.sql.Timestamp.class,
    68. new DateJsonValueProcessor("yyyy-MM-dd HH:mm:ss"));
    69. //将Date格式的时间对象转为"2016-03-25"格式的字符串
    70. jsonConfig.registerJsonValueProcessor(java.util.Date.class,
    71. new DateJsonValueProcessor("yyyy-MM-dd"));
    72. String json = JSONObject.fromObject(pageBean, jsonConfig).toString();
    73. System.out.println(json);
    74. // 使用输出流输出json数据到客户端
    75. ServletActionContext.getResponse().setContentType(
    76. "text/json;charset=UTF-8");
    77. try {
    78. ServletActionContext.getResponse().getWriter().print(json);
    79. } catch (IOException e) {
    80. e.printStackTrace();
    81. }
    82. }
    83. public void writePageBean2JsonToSession(PageBean pageBean, String[] excludes) {
    84. // 将PageBean对象转为json数据返回
    85. JsonConfig jsonConfig = new JsonConfig();
    86. jsonConfig.setExcludes(excludes);
    87. jsonConfig.setIgnoreDefaultExcludes(false);
    88. jsonConfig.registerJsonValueProcessor(java.sql.Date.class,
    89. new DateJsonValueProcessor("yyyy-MM-dd"));
    90. jsonConfig.registerJsonValueProcessor(java.sql.Timestamp.class,
    91. new DateJsonValueProcessor("yyyy-MM-dd hh:mm:ss"));
    92. //将Date格式的时间对象转为"2016-03-25"格式的字符串
    93. jsonConfig.registerJsonValueProcessor(java.util.Date.class,
    94. new DateJsonValueProcessor("yyyy-MM-dd"));
    95. String json = JSONObject.fromObject(pageBean, jsonConfig).toString();
    96. System.out.println(json);
    97. try {
    98. HttpServletRequest request = ServletActionContext.getRequest();
    99. request.setCharacterEncoding("UTF-8");
    100. HttpSession session = request.getSession();
    101. session.setAttribute("jsonData", json);
    102. } catch (UnsupportedEncodingException e1) {
    103. // TODO Auto-generated catch block
    104. e1.printStackTrace();
    105. }
    106. }
    107. /**
    108. * 将任意对象转为json数据返回给前台
    109. *
    110. * @param object
    111. * @param excludes
    112. */
    113. public void writeObject2Json(Object object, String[] excludes) {
    114. JsonConfig jsonConfig = new JsonConfig();
    115. jsonConfig.setExcludes(excludes);
    116. jsonConfig.setIgnoreDefaultExcludes(false);
    117. jsonConfig.registerJsonValueProcessor(java.sql.Date.class,
    118. new DateJsonValueProcessor("yyyy-MM-dd"));
    119. jsonConfig.registerJsonValueProcessor(java.sql.Timestamp.class,
    120. new DateJsonValueProcessor("yyyy-MM-dd hh:mm:ss"));
    121. //将Date格式的时间对象转为"2016-03-25"格式的字符串
    122. jsonConfig.registerJsonValueProcessor(java.util.Date.class,
    123. new DateJsonValueProcessor("yyyy-MM-dd"));
    124. String json = JSONObject.fromObject(object, jsonConfig).toString();
    125. System.out.println(json);
    126. // 使用输出流输出json数据到客户端
    127. ServletActionContext.getResponse().setContentType(
    128. "text/json;charset=UTF-8");
    129. try {
    130. ServletActionContext.getResponse().getWriter().print(json);
    131. } catch (IOException e) {
    132. e.printStackTrace();
    133. }
    134. }
    135. public void writePageBean2Json(List list, String[] excludes) {
    136. JsonConfig jsonConfig = new JsonConfig();
    137. jsonConfig.setExcludes(excludes);
    138. String json = JSONArray.fromObject(list, jsonConfig).toString();
    139. System.out.println(json);
    140. // 使用输出流输出json数据到客户端
    141. ServletActionContext.getResponse().setContentType(
    142. "text/json;charset=UTF-8");
    143. try {
    144. ServletActionContext.getResponse().getWriter().print(json);
    145. } catch (IOException e) {
    146. e.printStackTrace();
    147. }
    148. }
    149. }

    UserAction

    1. package com.deng.web.action;
    2. import java.io.IOException;
    3. import javax.annotation.Resource;
    4. import org.apache.struts2.ServletActionContext;
    5. import org.springframework.context.annotation.Scope;
    6. import org.springframework.stereotype.Controller;
    7. import com.deng.domain.User;
    8. import com.deng.service.IUserService;
    9. import com.deng.web.action.base.BaseAction;
    10. @Controller
    11. @Scope("prototype")
    12. public class UserAction extends BaseAction {
    13. @Resource
    14. private IUserService userService;
    15. //接收输入的验证码
    16. private String checkcode;
    17. public void setCheckcode(String checkcode) {
    18. this.checkcode = checkcode;
    19. }
    20. /**
    21. * 登录方法
    22. * @return
    23. */
    24. public String login(){
    25. //从Session中获取生成的验证码
    26. String key=(String) ServletActionContext.getRequest().getSession().getAttribute("key");
    27. //判断用户输入的验证码是否正确
    28. if (checkcode!=null&&checkcode.equals(key)) {
    29. //验证码输入正确,进行登陆校验
    30. User user=userService.login(model);
    31. if (user==null) {
    32. //登陆失败
    33. //设置错误提示信息
    34. this.addActionError("您输入用户名或密码错误,请重新登陆!");
    35. return LOGIN;
    36. }else if (user.getDeltag()==1) {
    37. //登陆失败
    38. //设置错误提示信息
    39. this.addActionError("此员工已离职,请重新登陆");
    40. return LOGIN;
    41. } else{
    42. //登陆成功,把用户对象存入Session
    43. ServletActionContext.getRequest().getSession().setAttribute("loginUser", user);
    44. //跳转到系统首页
    45. return "home";
    46. }
    47. }else{
    48. //验证码输入有误,设置错误提示信息
    49. this.addActionError(this.getText("您输入的验证码错误,请重新输入!"));
    50. //跳转到登陆页面
    51. return LOGIN;
    52. }
    53. }
    54. private int page;
    55. private int rows;
    56. public void setPage(int page) {
    57. this.page = page;
    58. }
    59. public void setRows(int rows) {
    60. this.rows = rows;
    61. }
    62. /**
    63. * 分页查询方法
    64. *
    65. * @return
    66. * @throws IOException
    67. */
    68. public String pageQuery() throws IOException{
    69. pageBean.setCurrentPage(page);
    70. pageBean.setPageSize(rows);
    71. userService.pageQuery(pageBean);
    72. this.writePageBean2Json(pageBean, new String[]{"wines","winesaves"});
    73. return NONE;
    74. }
    75. /**
    76. * 增加新的客户
    77. * @return
    78. */
    79. public String addUser(){
    80. userService.save(model);
    81. return "list";
    82. }
    83. /**
    84. * 修改密码
    85. * @return
    86. * @throws IOException
    87. */
    88. public String editPassword() throws IOException{
    89. String password=model.getPassword();//修改之后的密码
    90. User user=(User) ServletActionContext.getRequest().getSession().getAttribute("loginUser");
    91. String f="1";
    92. try {
    93. userService.editPassword(password,user.getId());
    94. } catch (Exception e) {
    95. f="0";
    96. }
    97. //向客户端浏览器写回数据
    98. ServletActionContext.getResponse().setContentType("text/html;charset=UTF-8");
    99. ServletActionContext.getResponse().getWriter().print(f);
    100. return NONE;
    101. }
    102. public String logout(){
    103. ServletActionContext.getRequest().getSession().invalidate();
    104. return "login";
    105. }
    106. private String ids;
    107. public void setIds(String ids) {
    108. this.ids = ids;
    109. }
    110. /**
    111. * 删除员工
    112. *
    113. * @return
    114. */
    115. public String delete(){
    116. userService.deleteBatch(ids);
    117. return "list";
    118. }
    119. /**
    120. * 员工重新上岗
    121. *
    122. * @return
    123. */
    124. public String up(){
    125. userService.upBatch(ids);
    126. return "list";
    127. }
    128. }

    WineAction

    1. package com.deng.web.action;
    2. import java.util.List;
    3. import javax.annotation.Resource;
    4. import org.apache.commons.lang.StringUtils;
    5. import org.hibernate.criterion.DetachedCriteria;
    6. import org.hibernate.criterion.Restrictions;
    7. import org.springframework.context.annotation.Scope;
    8. import org.springframework.stereotype.Controller;
    9. import com.deng.dao.impl.WineDaoImpl;
    10. import com.deng.domain.Wine;
    11. import com.deng.service.IWineService;
    12. import com.deng.web.action.base.BaseAction;
    13. @Controller
    14. @Scope("prototype")
    15. public class WineAction extends BaseAction {
    16. @Resource
    17. private IWineService wineService;
    18. private int page;
    19. private int rows;
    20. public void setPage(int page) {
    21. this.page = page;
    22. }
    23. public void setRows(int rows) {
    24. this.rows = rows;
    25. }
    26. /**
    27. * 带条件的分页查询
    28. *
    29. * @return
    30. */
    31. public String pageQuery(){
    32. DetachedCriteria dc=pageBean.getDetachedCriteria();
    33. String name=model.getName();
    34. if (StringUtils.isNotBlank(name)) {
    35. dc.add(Restrictions.like("name", "%"+name+"%"));
    36. }
    37. Integer deltag = model.getDeltag();
    38. if (deltag!=null) {
    39. dc.add(Restrictions.like("deltag", deltag));
    40. }
    41. String producingArea = model.getProducingArea();
    42. if (StringUtils.isNotBlank(producingArea)) {
    43. dc.add(Restrictions.like("producingArea", "%"+producingArea+"%"));
    44. }
    45. String depositPosition = model.getDepositPosition();
    46. if (StringUtils.isNotBlank(depositPosition)) {
    47. dc.add(Restrictions.like("depositPosition", "%"+depositPosition+"%"));
    48. }
    49. wineService.pageQuery(pageBean);
    50. this.writePageBean2Json(pageBean, new String[]{"imports","sales","wines","winesaves"});
    51. //this.writePageBean2Json(pageBean, new String[]{"decidedzone","subareas"});
    52. return NONE;
    53. }
    54. public String addWine(){
    55. wineService.save(model);
    56. return "list";
    57. }
    58. /**
    59. * 添加或更新酒水信息
    60. *
    61. * @return
    62. */
    63. public String addOrUpdateWine(){
    64. wineService.saveOrUpdate(model);
    65. return "list";
    66. }
    67. //删除功能
    68. private String ids;
    69. public void setIds(String ids) {
    70. this.ids = ids;
    71. }
    72. public String delete(){
    73. wineService.deleteBatch(ids);
    74. return "list";
    75. }
    76. /**
    77. * 酒水重新上架
    78. *
    79. * @return
    80. */
    81. public String up(){
    82. wineService.upBatch(ids);
    83. return "list";
    84. }
    85. public String ajaxlist(){
    86. List list=wineService.findAll();
    87. this.writePageBean2Json(list, new String[]{"imports","sales","wines","winesaves","user"});
    88. return NONE;
    89. }
    90. /**
    91. * 根据酒水id查询酒水信息,并返回json字符串,用于前台修改酒水
    92. *
    93. * @return
    94. */
    95. public String queryWineByIdToJson(){
    96. Wine wine=wineService.queryWineById(model.getId());
    97. this.writeObject2Json(wine,new String[]{"imports","sales","wines","winesaves"} );
    98. return NONE;
    99. }
    100. }

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

  • 相关阅读:
    总结了一份Java架构师核心知识点PDF丨粉丝福利
    Spring整合RabbitMQ-配制文件方式-3-消息拉模式
    代码随想录算法训练营第五十七天 | 动态规划 part 15 | 392.判断子序列、115.不同的子序列
    Unity自动导出包
    GPT-4V:AI在医疗领域的应用
    【JVM】JDBC案例打破双亲委派机制
    HTTP协议
    Python与数据分析--Pandas操作进阶
    支持百万并发的Web端即时通讯方案
    湖北省组织申报国家火炬特色产业基地条件、流程梳理
  • 原文地址:https://blog.csdn.net/hanyunlong1989/article/details/127132088