作者主页:夜未央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
package com.deng.web.action.base;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import org.apache.struts2.ServletActionContext;
import org.hibernate.criterion.DetachedCriteria;
import com.deng.domain.PageBean;
import com.deng.utils.DateJsonValueProcessor;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
public class BaseAction<T> extends ActionSupport implements ModelDriven<T> {
private static final long serialVersionUID = 6788265612879264198L;
// 定义模型对象
protected T model;
// 返回模型对象
public T getModel() {
return model;
}
protected PageBean pageBean = new PageBean();
private int page;
private int rows;
public void setPage(int page) {
this.page = page;
}
public void setRows(int rows) {
this.rows = rows;
}
DetachedCriteria detachedCriteria = null;
public BaseAction() {
// 获得父类的类型(BaseAction)
ParameterizedType genericSuperclass = (ParameterizedType) this
.getClass().getGenericSuperclass();
// 获得BaseAction上声明的泛型数组
Type[] actualTypeArguments = genericSuperclass.getActualTypeArguments();
// 实体类型
Class<T> entityClass = (Class<T>) actualTypeArguments[0];
detachedCriteria = DetachedCriteria.forClass(entityClass);
pageBean.setDetachedCriteria(detachedCriteria);
// 通过反射创建model对象
try {
model = entityClass.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
/**
* 将PageBean对象转为json数据返回
*
* @param pageBean
* @param excludes
*/
public void writePageBean2Json(PageBean pageBean, String[] excludes) {
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setExcludes(excludes);
jsonConfig.setIgnoreDefaultExcludes(false);
jsonConfig.registerJsonValueProcessor(java.sql.Date.class,
new DateJsonValueProcessor("yyyy-MM-dd"));
jsonConfig.registerJsonValueProcessor(java.sql.Timestamp.class,
new DateJsonValueProcessor("yyyy-MM-dd HH:mm:ss"));
//将Date格式的时间对象转为"2016-03-25"格式的字符串
jsonConfig.registerJsonValueProcessor(java.util.Date.class,
new DateJsonValueProcessor("yyyy-MM-dd"));
String json = JSONObject.fromObject(pageBean, jsonConfig).toString();
System.out.println(json);
// 使用输出流输出json数据到客户端
ServletActionContext.getResponse().setContentType(
"text/json;charset=UTF-8");
try {
ServletActionContext.getResponse().getWriter().print(json);
} catch (IOException e) {
e.printStackTrace();
}
}
public void writePageBean2JsonToSession(PageBean pageBean, String[] excludes) {
// 将PageBean对象转为json数据返回
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setExcludes(excludes);
jsonConfig.setIgnoreDefaultExcludes(false);
jsonConfig.registerJsonValueProcessor(java.sql.Date.class,
new DateJsonValueProcessor("yyyy-MM-dd"));
jsonConfig.registerJsonValueProcessor(java.sql.Timestamp.class,
new DateJsonValueProcessor("yyyy-MM-dd hh:mm:ss"));
//将Date格式的时间对象转为"2016-03-25"格式的字符串
jsonConfig.registerJsonValueProcessor(java.util.Date.class,
new DateJsonValueProcessor("yyyy-MM-dd"));
String json = JSONObject.fromObject(pageBean, jsonConfig).toString();
System.out.println(json);
try {
HttpServletRequest request = ServletActionContext.getRequest();
request.setCharacterEncoding("UTF-8");
HttpSession session = request.getSession();
session.setAttribute("jsonData", json);
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
/**
* 将任意对象转为json数据返回给前台
*
* @param object
* @param excludes
*/
public void writeObject2Json(Object object, String[] excludes) {
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setExcludes(excludes);
jsonConfig.setIgnoreDefaultExcludes(false);
jsonConfig.registerJsonValueProcessor(java.sql.Date.class,
new DateJsonValueProcessor("yyyy-MM-dd"));
jsonConfig.registerJsonValueProcessor(java.sql.Timestamp.class,
new DateJsonValueProcessor("yyyy-MM-dd hh:mm:ss"));
//将Date格式的时间对象转为"2016-03-25"格式的字符串
jsonConfig.registerJsonValueProcessor(java.util.Date.class,
new DateJsonValueProcessor("yyyy-MM-dd"));
String json = JSONObject.fromObject(object, jsonConfig).toString();
System.out.println(json);
// 使用输出流输出json数据到客户端
ServletActionContext.getResponse().setContentType(
"text/json;charset=UTF-8");
try {
ServletActionContext.getResponse().getWriter().print(json);
} catch (IOException e) {
e.printStackTrace();
}
}
public void writePageBean2Json(List list, String[] excludes) {
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setExcludes(excludes);
String json = JSONArray.fromObject(list, jsonConfig).toString();
System.out.println(json);
// 使用输出流输出json数据到客户端
ServletActionContext.getResponse().setContentType(
"text/json;charset=UTF-8");
try {
ServletActionContext.getResponse().getWriter().print(json);
} catch (IOException e) {
e.printStackTrace();
}
}
}
UserAction
package com.deng.web.action;
import java.io.IOException;
import javax.annotation.Resource;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.deng.domain.User;
import com.deng.service.IUserService;
import com.deng.web.action.base.BaseAction;
@Controller
@Scope("prototype")
public class UserAction extends BaseAction<User> {
@Resource
private IUserService userService;
//接收输入的验证码
private String checkcode;
public void setCheckcode(String checkcode) {
this.checkcode = checkcode;
}
/**
* 登录方法
* @return
*/
public String login(){
//从Session中获取生成的验证码
String key=(String) ServletActionContext.getRequest().getSession().getAttribute("key");
//判断用户输入的验证码是否正确
if (checkcode!=null&&checkcode.equals(key)) {
//验证码输入正确,进行登陆校验
User user=userService.login(model);
if (user==null) {
//登陆失败
//设置错误提示信息
this.addActionError("您输入用户名或密码错误,请重新登陆!");
return LOGIN;
}else if (user.getDeltag()==1) {
//登陆失败
//设置错误提示信息
this.addActionError("此员工已离职,请重新登陆");
return LOGIN;
} else{
//登陆成功,把用户对象存入Session
ServletActionContext.getRequest().getSession().setAttribute("loginUser", user);
//跳转到系统首页
return "home";
}
}else{
//验证码输入有误,设置错误提示信息
this.addActionError(this.getText("您输入的验证码错误,请重新输入!"));
//跳转到登陆页面
return LOGIN;
}
}
private int page;
private int rows;
public void setPage(int page) {
this.page = page;
}
public void setRows(int rows) {
this.rows = rows;
}
/**
* 分页查询方法
*
* @return
* @throws IOException
*/
public String pageQuery() throws IOException{
pageBean.setCurrentPage(page);
pageBean.setPageSize(rows);
userService.pageQuery(pageBean);
this.writePageBean2Json(pageBean, new String[]{"wines","winesaves"});
return NONE;
}
/**
* 增加新的客户
* @return
*/
public String addUser(){
userService.save(model);
return "list";
}
/**
* 修改密码
* @return
* @throws IOException
*/
public String editPassword() throws IOException{
String password=model.getPassword();//修改之后的密码
User user=(User) ServletActionContext.getRequest().getSession().getAttribute("loginUser");
String f="1";
try {
userService.editPassword(password,user.getId());
} catch (Exception e) {
f="0";
}
//向客户端浏览器写回数据
ServletActionContext.getResponse().setContentType("text/html;charset=UTF-8");
ServletActionContext.getResponse().getWriter().print(f);
return NONE;
}
public String logout(){
ServletActionContext.getRequest().getSession().invalidate();
return "login";
}
private String ids;
public void setIds(String ids) {
this.ids = ids;
}
/**
* 删除员工
*
* @return
*/
public String delete(){
userService.deleteBatch(ids);
return "list";
}
/**
* 员工重新上岗
*
* @return
*/
public String up(){
userService.upBatch(ids);
return "list";
}
}
WineAction
package com.deng.web.action;
import java.util.List;
import javax.annotation.Resource;
import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.deng.dao.impl.WineDaoImpl;
import com.deng.domain.Wine;
import com.deng.service.IWineService;
import com.deng.web.action.base.BaseAction;
@Controller
@Scope("prototype")
public class WineAction extends BaseAction<Wine> {
@Resource
private IWineService wineService;
private int page;
private int rows;
public void setPage(int page) {
this.page = page;
}
public void setRows(int rows) {
this.rows = rows;
}
/**
* 带条件的分页查询
*
* @return
*/
public String pageQuery(){
DetachedCriteria dc=pageBean.getDetachedCriteria();
String name=model.getName();
if (StringUtils.isNotBlank(name)) {
dc.add(Restrictions.like("name", "%"+name+"%"));
}
Integer deltag = model.getDeltag();
if (deltag!=null) {
dc.add(Restrictions.like("deltag", deltag));
}
String producingArea = model.getProducingArea();
if (StringUtils.isNotBlank(producingArea)) {
dc.add(Restrictions.like("producingArea", "%"+producingArea+"%"));
}
String depositPosition = model.getDepositPosition();
if (StringUtils.isNotBlank(depositPosition)) {
dc.add(Restrictions.like("depositPosition", "%"+depositPosition+"%"));
}
wineService.pageQuery(pageBean);
this.writePageBean2Json(pageBean, new String[]{"imports","sales","wines","winesaves"});
//this.writePageBean2Json(pageBean, new String[]{"decidedzone","subareas"});
return NONE;
}
public String addWine(){
wineService.save(model);
return "list";
}
/**
* 添加或更新酒水信息
*
* @return
*/
public String addOrUpdateWine(){
wineService.saveOrUpdate(model);
return "list";
}
//删除功能
private String ids;
public void setIds(String ids) {
this.ids = ids;
}
public String delete(){
wineService.deleteBatch(ids);
return "list";
}
/**
* 酒水重新上架
*
* @return
*/
public String up(){
wineService.upBatch(ids);
return "list";
}
public String ajaxlist(){
List<Wine> list=wineService.findAll();
this.writePageBean2Json(list, new String[]{"imports","sales","wines","winesaves","user"});
return NONE;
}
/**
* 根据酒水id查询酒水信息,并返回json字符串,用于前台修改酒水
*
* @return
*/
public String queryWineByIdToJson(){
Wine wine=wineService.queryWineById(model.getId());
this.writeObject2Json(wine,new String[]{"imports","sales","wines","winesaves"} );
return NONE;
}
}
如果也想学习本系统,下面领取。关注并回复:126ssh