基于javaweb+mysql的jsp+servlet大学实验室设备管理系统(java+jsp+easyui+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的JSP+Servlet大学实验室设备管理系统(java+jsp+easyui+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.数据库:MySql 5.7版本; 6.是否Maven项目:否;
技术栈
HTML+CSS+JavaScript+JSP+jquery+easyui+mysql
使用说明
*/
public synchronized Connection getConnection() {
if (pool.size() > 0) {
Connection conn = pool.get(0);
pool.remove(conn);
return conn;
} else {
return null;
}
}
/**
* 在连接池中创建初始设置的数据库连接
*/
private void addConnection() {
Connection conn = null;
for (int i = 0; i < poolSize; i++) {
try {
Class.forName(driverClassName);
conn = java.sql.DriverManager.getConnection(url, username, password);
pool.add(conn);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
private void readConfig() {
try {
//String path = System.getProperty("user.dir") + "\\src\\dbpool.properties"; // 路径
/**
* 加载配置文件
*/
// FileInputStream is = new FileInputStream(path);
Properties props = new Properties();
props.load(getClass().getResourceAsStream("/dbpool.properties"));
/**
* 读取属性值
*/
this.driverClassName = props.getProperty("driverClassName"); // 读取数据库类型
* @param dictionaryId
* @return
* @throws SQLException
*/
public boolean getGoodsByDictionaryId(Connection conn, String dictionaryId) throws SQLException {
String sql = "SELECT * FROM t_goods WHERE typeid = ? or supplierid = ?";
PreparedStatement pstm = conn.prepareStatement(sql);
int id = Integer.parseInt(dictionaryId);
pstm.setInt(1, id);
pstm.setInt(2, id);
ResultSet rs = pstm.executeQuery();
if(rs.next()) {
return true;
} else {
return false;
}
}
}
package com.wbstar.jxc.action;
@SuppressWarnings("serial")
public class GoodsAction extends ActionSupport{
private String page; // 第几页
private String rows; // 每页记录数
private String s_goodsname = ""; // 搜索商品名
* @return
* @throws SQLException
*/
public int dictionaryAdd(Connection conn, Dictionary dictionary) throws SQLException {
String sql = "INSERT INTO t_dictionary (name, value, remark) VALUES (?, ?, ?)";
PreparedStatement pstm = conn.prepareStatement(sql);
pstm.setString(1, dictionary.getName());
pstm.setString(2, dictionary.getValue());
pstm.setString(3, dictionary.getRemark());
return pstm.executeUpdate();
}
/**
* 修改数据字典记录
* @param conn
* @param dictionary
* @return
* @throws SQLException
*/
public int dictionaryModify(Connection conn, Dictionary dictionary) throws SQLException {
String sql = "UPDATE t_dictionary SET name = ?, value = ?, remark = ? WHERE id = ?";
PreparedStatement pstm = conn.prepareStatement(sql);
pstm.setString(1, dictionary.getName());
pstm.setString(2, dictionary.getValue());
pstm.setString(3, dictionary.getRemark());
pstm.setInt(4, dictionary.getId());
return pstm.executeUpdate();
}
}
package com.wbstar.jxc.service;
public class KucunService {
/**
* 库存记录
* @param conn
* @param pageBean
* @param kucun
* @return
* @throws SQLException
*/
public ResultSet kucunList (Connection conn, PageBean pageBean, Kucun kucun) throws SQLException {
StringBuffer sb = new StringBuffer("SELECT * FROM t_kucun k , t_goods g WHERE k.goodsid = g.goodsid");
this.pool.release(connection);
} catch (SQLException e) {
e.printStackTrace();
logger.error("关闭数据库连接时出现异常!");
}
}
}
package com.wbstar.jxc.model;
public class Jinhuo {
private int id; // 编号
private int goodsid = -1; // 商品实体对象ID
private int quantity; // 进货数量
private Date intodate; // 进货时间
private String goodsname; // 商品名称
/**********************GETTER/SETTER***********************/
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getGoodsid() {
return goodsid;
}
public void setGoodsid(int goodsid) {
this.goodsid = goodsid;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public Date getIntodate() {
Connection conn = dbUtil.getConnection();
String sql = "UPDATE t_goods SET goodsname = ? , cost = ? , sell = ? , supplierId = ? , supplier = ? , typeId = ? , type = ? WHERE goodsid = ?";
PreparedStatement pstm = null;
try {
pstm = conn.prepareStatement(sql);
pstm.setString(1, goods.getGoodsname());
pstm.setFloat(2, goods.getCost());
pstm.setFloat(3, goods.getSell());
pstm.setInt(4, goods.getSupplierId());
pstm.setString(5, goods.getSupplier());
pstm.setInt(6, goods.getTypeId());
pstm.setString(7, goods.getType());
pstm.setInt(8, goods.getGoodsid());
num = pstm.executeUpdate();
} catch (Exception e) {
} finally {
dbUtil.close(conn, pstm, rs);
}
return num;
}
/**
* 查找商品记录 通过数据字典ID
* @param conn
* @param dictionaryId
* @return
* @throws SQLException
*/
public boolean getGoodsByDictionaryId(Connection conn, String dictionaryId) throws SQLException {
String sql = "SELECT * FROM t_goods WHERE typeid = ? or supplierid = ?";
PreparedStatement pstm = conn.prepareStatement(sql);
int id = Integer.parseInt(dictionaryId);
pstm.setInt(1, id);
pstm.setInt(2, id);
ResultSet rs = pstm.executeQuery();
if(rs.next()) {
return true;
} else {
return false;
}
}
}
package com.wbstar.jxc.action;
table>
td>
<td> td>
tr>
table>
td>
tr>
table>
td>
tr>
<tr>
<td bgcolor="#a2d962"> td>
tr>
table>
body>
html>
<%@ page language="java" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
%>
DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
a:link {text-decoration:none; color:black;} /* 未被访问的链接 */
a:visited {text-decoration:none; color:black;} /* 已被访问的链接 */
a:hover {text-decoration:none; color:red;} /* 鼠标指针移动到链接上 */
a:active {text-decoration:none; color:red;} /* 正在被点击的链接 */
style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>大学固定资产管理系统title>
<%
//权限验证
if(session.getAttribute("currentuser") == null){
response.sendRedirect("/jsp_dxsys_sys/dynamic/server/view/login.jsp");
return;
}
%>
<jsp:include page="/dynamic/link/base.jsp">jsp:include>
<script type="text/javascript">
$(function(){
} else {
return false;
}
}
}
package com.wbstar.jxc.action;
@SuppressWarnings("serial")
public class GoodsAction extends ActionSupport{
private String page; // 第几页
private String rows; // 每页记录数
private String s_goodsname = ""; // 搜索商品名
private String s_supplier = ""; // 搜索供应商
private String s_type = ""; // 搜索商品类型
private Goods goods; // 商品
private String delIds; // 批量删除ID号
private String goodsid; // 商品ID
DBUtil dbUtil = new DBUtil();
GoodsService goodsService = new GoodsService();
public String execute() throws Exception{
PageBean pageBean = new PageBean(Integer.parseInt(page), Integer.parseInt(rows));
Connection conn = dbUtil.getConnection();
if (goods == null) {
goods = new Goods();
/** 获取连接对象 */
public Connection getConnection() {
conn = pool.getConnection();
return conn;
}
/** 关闭流,释放连接 */
public void close(Connection connection, PreparedStatement statement, ResultSet result) {
try {
if (result != null)
result.close();
if (statement != null)
statement.close();
if (connection != null)
this.pool.release(connection);
} catch (SQLException e) {
e.printStackTrace();
logger.error("关闭数据库连接时出现异常!");
}
}
}
package com.wbstar.jxc.model;
public class Jinhuo {
private int id; // 编号
private int goodsid = -1; // 商品实体对象ID
private int quantity; // 进货数量
private Date intodate; // 进货时间
private String goodsname; // 商品名称
/**********************GETTER/SETTER***********************/
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getGoodsid() {
int total = 0;
PageBean pageBean = new PageBean (Integer.parseInt(page), Integer.parseInt(rows));
User user = (User)session.getAttribute("currentuser");
total = userService.getTotal(user, s_username);
JSONObject result = new JSONObject();
JSONArray jsonArray = JsonUtil.formatRsToJsonArray(userService.queryForAll(user, pageBean, s_username));
result.put("rows", jsonArray);
result.put("total", total);
ResponseUtil.write(ServletActionContext.getResponse(), result);
return null;
}
public String delete()throws Exception{
JSONObject result=new JSONObject();
int delNums=userService.delete(delIds);
if(delNums>0){
result.put("success", "true");
result.put("delNums", delNums);
}else{
result.put("errorMsg", "删除失败");
}
ResponseUtil.write(ServletActionContext.getResponse(), result);
return null;
}
public String save()throws Exception{
int saveNums=0;
JSONObject result=new JSONObject();
if(StringUtil.isNotEmpty(id)){
user.setId(Integer.parseInt(id));
saveNums = userService.update(user);
} else {
saveNums = userService.insert(user);
}
if(saveNums>0){
result.put("success", "true");
}else{
result.put("success", "true");
result.put("errorMsg", "保存失败");
}
ResponseUtil.write(ServletActionContext.getResponse(), result);
return null;
}
//===============GET,SET====================
public class Goods {
private int goodsid; // 编号
private String goodsname; // 商品名
private float cost; // 成本
private float sell; // 售价
private int supplierId; // 供应商ID
private String supplier; // 供应商名
private int typeId; // 商品类型ID
private String type; // 商品类型名
/**************** GETTER/SETTER ***************/
public int getGoodsid() {
return goodsid;
}
public void setGoodsid(int goodsid) {
this.goodsid = goodsid;
}
public String getGoodsname() {
return goodsname;
}
public void setGoodsname(String goodsname) {
this.goodsname = goodsname;
}
public float getCost() {
return cost;
}
public void setCost(float cost) {
this.cost = cost;
}
public float getSell() {
return sell;
}
public void setSell(float sell) {
this.sell = sell;
}
public int getSupplierId() {
public String getS_type() {
return s_type;
}
public void setS_type(String s_type) {
this.s_type = s_type;
}
public Goods getGoods() {
return goods;
}
public void setGoods(Goods goods) {
this.goods = goods;
}
public String getDelIds() {
return delIds;
}
public void setDelIds(String delIds) {
this.delIds = delIds;
}
public String getGoodsid() {
return goodsid;
}
public void setGoodsid(String goodsid) {
this.goodsid = goodsid;
}
}
package com.wbstar.jxc.action;
<style type="text/css">
a:link {text-decoration:none; color:black;} /* 未被访问的链接 */
a:visited {text-decoration:none; color:black;} /* 已被访问的链接 */
a:hover {text-decoration:none; color:red;} /* 鼠标指针移动到链接上 */
a:active {text-decoration:none; color:red;} /* 正在被点击的链接 */
style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>大学固定资产管理系统title>
<%
//权限验证
if(session.getAttribute("currentuser") == null){
response.sendRedirect("/jsp_dxsys_sys/dynamic/server/view/login.jsp");
return;
}
%>
<jsp:include page="/dynamic/link/base.jsp">jsp:include>
<script type="text/javascript">
$(function(){
// 数据
var treeData=[{
text:"大学资产管理系统",
children:[{
text:"数据字典",
attributes:{
url:"<%=path %>/dynamic/server/dictionary/page.jsp"
}
},{
text:"设备信息管理",
attributes:{
url:"<%=path %>/dynamic/server/goods/page.jsp"
}
},{
text:"进购管理",
attributes:{
url:"<%=path %>/dynamic/server/jinhuo/page.jsp"
}
},{
text:"报损管理",
attributes:{
url:"<%=path %>/dynamic/server/chuhuo/page.jsp"
private String rows; // 每页记录数
private Jinhuo jinhuo; // 进货单
private String id; // 进货单ID
private String s_goodsid; // 搜索商品ID
private String s_intodate; // 搜索下单日期
DBUtil dbUtil = new DBUtil();
ResultSet rs = null;
JinhuoService jinhuoService = new JinhuoService();
KucunService kucunService = new KucunService();
public String execute() throws SQLException {
Connection conn = dbUtil.getConnection();
PageBean pageBean = new PageBean (Integer.parseInt(page), Integer.parseInt(rows));
JSONObject result = new JSONObject();
JSONArray jsonArray;
try {
if(jinhuo == null){
jinhuo = new Jinhuo();
}
if(StringUtil.isNotEmpty(s_goodsid)){
jinhuo.setGoodsid(Integer.parseInt(s_goodsid));
}
jsonArray = JsonUtil.formatRsToJsonArray(jinhuoService.jinhuoList(conn, pageBean, jinhuo, s_intodate));
int total = jinhuoService.jinhuoListTotal(conn, jinhuo, s_intodate);
result.put("rows", jsonArray);
result.put("total", total);
ResponseUtil.write(ServletActionContext.getResponse(), result);
} catch (Exception e) {
e.printStackTrace();
} finally {
dbUtil.close(conn, null, rs);
}
return null;
}
public String save() throws Exception {
Connection conn = dbUtil.getConnection();
Kucun currentkucun = null;
pstm.setInt(4, goods.getSupplierId());
pstm.setString(5, goods.getSupplier());
pstm.setInt(6, goods.getTypeId());
pstm.setString(7, goods.getType());
num = pstm.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
dbUtil.close(conn, pstm, rs);
}
return num;
}
/**
* 修改商品记录
* @param goods
* @return
*/
public int goodsModify (Goods goods) {
int num = 0;
Connection conn = dbUtil.getConnection();
String sql = "UPDATE t_goods SET goodsname = ? , cost = ? , sell = ? , supplierId = ? , supplier = ? , typeId = ? , type = ? WHERE goodsid = ?";
PreparedStatement pstm = null;
try {
pstm = conn.prepareStatement(sql);
pstm.setString(1, goods.getGoodsname());
pstm.setFloat(2, goods.getCost());
pstm.setFloat(3, goods.getSell());
pstm.setInt(4, goods.getSupplierId());
pstm.setString(5, goods.getSupplier());
pstm.setInt(6, goods.getTypeId());
pstm.setString(7, goods.getType());
pstm.setInt(8, goods.getGoodsid());
num = pstm.executeUpdate();
} catch (Exception e) {
} finally {
dbUtil.close(conn, pstm, rs);
}
return num;
}
result.put("delNums", delNums);
} else {
result.put("errorMsg", "删除失败");
}
try {
ResponseUtil.write(ServletActionContext.getResponse(), result);
} catch (Exception e) {
e.printStackTrace();
throw (e);
}
return null;
}
public String save() throws Exception {
if (StringUtil.isNotEmpty(goodsid)) {
goods.setGoodsid(Integer.parseInt(goodsid));
}
int saveNums = 0;
JSONObject result = new JSONObject();
if (StringUtil.isNotEmpty(goodsid)) {
saveNums = goodsService.goodsModify(goods);
} else {
saveNums = goodsService.goodsAdd(goods);
}
if (saveNums > 0) {
result.put("success", "true");
} else {
result.put("success", "true");
result.put("errorMsg", "保存失败");
}
try {
ResponseUtil.write(ServletActionContext.getResponse(), result);
} catch (Exception e) {
e.printStackTrace();
throw (e);
}
return null;
}
public String goodsComboList() throws Exception{
Connection conn = dbUtil.getConnection();
JSONArray jsonArray = new JSONArray();
JSONObject jsonObject = new JSONObject();
jsonObject.put("goodsid", "");
jsonObject.put("goodsname", "请选择...");
jsonArray.add(jsonObject);
try {
jsonArray.addAll(JsonUtil.formatRsToJsonArray(goodsService.goodsList(null, null,conn)));
ResponseUtil.write(ServletActionContext.getResponse(), jsonArray);
} catch (Exception e) {
e.printStackTrace();
}finally{
* @param kucun
* @return
* @throws SQLException
*/
public ResultSet kucunList (Connection conn, PageBean pageBean, Kucun kucun) throws SQLException {
StringBuffer sb = new StringBuffer("SELECT * FROM t_kucun k , t_goods g WHERE k.goodsid = g.goodsid");
if(pageBean != null){
sb.append(" LIMIT "+ pageBean.getStart() +","+ pageBean.getRows());
}
PreparedStatement pstm = conn.prepareStatement(sb.toString());
return pstm.executeQuery();
}
/**
* 库存记录条数
* @param conn
* @param kucun
* @return
* @throws SQLException
*/
public int kucunListTotal (Connection conn, Kucun kucun) throws SQLException {
StringBuffer sb = new StringBuffer("SELECT COUNT(*) AS total FROM t_kucun k , t_goods g WHERE k.goodsid = g.goodsid");
PreparedStatement pstm = conn.prepareStatement(sb.toString());
ResultSet rs = pstm.executeQuery();
if(rs.next()){
return rs.getInt("total");
} else {
return 0;
}
}
/**
* 查找库存中是否用进货单中的商品
* @param conn
* @param goodsid
* @return
* @throws SQLException
*/
public Kucun queryKucunByGoodsid (Connection conn, int goodsid) throws SQLException {
Kucun currentkucun = null;
String sql = "SELECT * from t_kucun k WHERE goodsid = ?";
PreparedStatement pstm = conn.prepareStatement(sql);
pstm.setInt(1, goodsid);
ResultSet rs = pstm.executeQuery();
if(rs.next()){
currentkucun = new Kucun();
kucunService.kucunModify(conn, currentkucun);
}
if (StringUtil.isNotEmpty(id)){
jinhuo.setId(Integer.parseInt(id));
}
int saveNums = 0;
JSONObject result = new JSONObject();
if (StringUtil.isNotEmpty(id)) {
saveNums = jinhuoService.jinhuoModify(conn, jinhuo);
} else {
saveNums = jinhuoService.jinhuoAdd(conn, jinhuo);
}
if (saveNums > 0) {
result.put("success", "true");
} else {
result.put("success", "ture");
result.put("errorMsg", "保存失败");
}
try {
ResponseUtil.write(ServletActionContext.getResponse(), result);
} catch (Exception e) {
e.printStackTrace();
throw (e);
} finally {
dbUtil.close(conn, null, rs);
}
return null;
}
/*********************GETTER/SETTER*******************/
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
public String getRows() {
return rows;
}
public void setRows(String rows) {
this.rows = rows;
}
public Jinhuo getJinhuo() {
return jinhuo;
}
public void setJinhuo(Jinhuo jinhuo) {
this.jinhuo = jinhuo;
}
public String getId() {
return id;
}
public void setId(String id) {
<td width="255"
background="<%=basePath%>/statics/skin/server/images/login/login_08.gif"> td>
tr>
form>
table>
td>
tr>
<tr>
<td height="247" valign="top"
background="<%=basePath%>/statics/skin/server/images/login/login_09.gif"><table
width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="22%" height="30"> td>
<td width="56%">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="57%">td>
<td algin="left"><span class="STYLE5" >${error} span>
td>
tr>
table>
td>
<td width="22%"> td>
tr>
<tr>
<td> td>
<td height="30"><table width="100%" border="0"
cellspacing="0" cellpadding="0">
<tr>
<td width="44%" height="20"> td>
tr>
table>
td>
<td> td>
tr>
table>
td>
tr>
table>
td>
tr>
<tr>
<td bgcolor="#a2d962"> td>
tr>
table>
body>
html>
<%@ page language="java" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
private String imageCode;
private String old_password;
UserService userService = new UserService();
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session;
public void setServletRequest(HttpServletRequest request) {
// TODO Auto-generated method stub
this.request = request;
//获取Session
session = request.getSession();
}
public String index() {
if(StringUtil.isEmpty(user.getUsername()) || StringUtil.isEmpty(user.getPassword())){
error = "用户名或密码为空!";
return ERROR;
}
if(StringUtil.isEmpty(imageCode)) {
error = "验证码为空!";
return ERROR;
}
if(!imageCode.equals(session.getAttribute("sRand"))) {
error = "验证码错误!";
return ERROR;
}
User currentuser = userService.login(user);
if(currentuser == null) {
error = "用户名或密码错误!";
return ERROR;
} else {
session = request.getSession();
session.setAttribute("currentuser", currentuser);
return SUCCESS;
}
}
public String logout() {
return "logout";
}
@Override
public String execute() throws Exception {
int total = 0;
PageBean pageBean = new PageBean (Integer.parseInt(page), Integer.parseInt(rows));
User user = (User)session.getAttribute("currentuser");
total = userService.getTotal(user, s_username);
}
if(StringUtil.isNotEmpty(s_type)){
goods.setType(s_type);
}
int total = goodsService.goodsListTotal(goods,conn);
JSONObject result = new JSONObject();
JSONArray jsonArray = null;
try {
jsonArray = JsonUtil.formatRsToJsonArray(goodsService.goodsList(pageBean, goods,conn)); // 将结果集转为json数组
result.put("rows", jsonArray);
result.put("total", total);
ResponseUtil.write(ServletActionContext.getResponse(), result);
} catch (Exception e) {
e.printStackTrace();
throw e;
}finally{
dbUtil.close(conn, null, null);
}
return null;
}
public String delete() throws Exception {
JSONObject result = new JSONObject();
int delNums = goodsService.goodsDelete(delIds);
if (delNums > 0) {
result.put("success", "true");
result.put("delNums", delNums);
} else {
result.put("errorMsg", "删除失败");
}
try {
ResponseUtil.write(ServletActionContext.getResponse(), result);
} catch (Exception e) {
e.printStackTrace();
throw (e);
}
return null;
}
public String save() throws Exception {
if (StringUtil.isNotEmpty(goodsid)) {
document.getElementById("imageCode").value="";
}
function loadimage(){
document.getElementById("randImage").src = "<%=basePath%>/dynamic/server/view/image.jsp?"+Math.random();
}
script>
head>
<body>
<table width="100%" height="100%" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td bgcolor="#e5f6cf"> td>
tr>
<tr>
<td height="608"
background="<%=basePath%>/statics/skin/server/images/login/login_03.gif"><table
width="862" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td height="266"
background="<%=basePath%>/statics/skin/server/images/login/login_04.gif"> td>
tr>
<tr>
<td height="95">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<form action="<%=basePath%>/server/index.action" method="post" id="submitForm">
<tr>
<td width="424" height="95"
background="<%=basePath%>/statics/skin/server/images/login/login_06.gif"> td>
<td width="183"
background="<%=basePath%>/statics/skin/server/images/login/login_07.gif">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="21%" height="18"><div align="center">
<span class="STYLE3">用 户span>
div>td>
<td width="79%" height="18"><input type="text"
name="user.username" id="username"
style="height: 15px; width: 130px; border: solid 1px #cadcb2; font-size: 12px; color: #81b432;">
td>
tr>
<tr>
* @return
*/
public int goodsDelete (String delIds) {
int num = 0;
Connection conn = dbUtil.getConnection();
String sql = "DELETE FROM t_goods WHERE goodsid IN ("+ delIds +")";
PreparedStatement pstm = null;
try {
pstm = conn.prepareStatement(sql);
num = pstm.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
dbUtil.close(conn, pstm, rs);
}
return num;
}
/**
* 添加商品记录
* @param goods
* @return
*/
public int goodsAdd(Goods goods) {
int num = 0;
Connection conn = dbUtil.getConnection();
String sql = "INSERT INTO t_goods (goodsname, cost, sell, supplierId, supplier, typeId, type) VALUES (?, ?, ?, ?, ?, ?, ?)";
PreparedStatement pstm = null;
try {
pstm = conn.prepareStatement(sql);
pstm.setString(1, goods.getGoodsname());
pstm.setFloat(2, goods.getCost());
pstm.setFloat(3, goods.getSell());
pstm.setInt(4, goods.getSupplierId());
pstm.setString(5, goods.getSupplier());
pstm.setInt(6, goods.getTypeId());
pstm.setString(7, goods.getType());
num = pstm.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
dbUtil.close(conn, pstm, rs);
}
return num;
}
rs = pstm.executeQuery();
if(!rs.next()) {
flag = true;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
dbUtil.close(conn, pstm, rs);
}
return flag;
}
}
package com.wbstar.jxc.action;
public class DictionaryAction {
private String page; // 第几页
private String rows; // 每页记录数
private String s_name="";
private String s_value="";
private Dictionary dictionary;
private String delIds;
private String id;
private String name;
DBUtil dbUtil = new DBUtil();
ResultSet rs = null;
DictionaryService dictionaryService = new DictionaryService();
GoodsService goodsService = new GoodsService();
public String execute() throws SQLException {
if (connection != null)
this.pool.release(connection);
} catch (SQLException e) {
e.printStackTrace();
logger.error("关闭数据库连接时出现异常!");
}
}
}
package com.wbstar.jxc.model;
public class Jinhuo {
private int id; // 编号
private int goodsid = -1; // 商品实体对象ID
private int quantity; // 进货数量
private Date intodate; // 进货时间
private String goodsname; // 商品名称
/**********************GETTER/SETTER***********************/
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getGoodsid() {
return goodsid;
}
public void setGoodsid(int goodsid) {
this.goodsid = goodsid;
}
public int getQuantity() {
return quantity;
ResultSet rs = null;
/**
* 登录验证
*
* @param user
* @return User
*/
public User login (User user) {
Connection conn = dbUtil.getConnection();
String sql = "select * from t_user where username=? and password=?";
User u = null;
PreparedStatement pstm = null;
try {
pstm = conn.prepareStatement(sql);
pstm.setString(1, user.getUsername());
pstm.setString(2, user.getPassword());
rs = pstm.executeQuery();
while(rs.next()) {
u = new User();
u.initFormRs(rs);
}
}catch (SQLException e) {
e.printStackTrace();
} finally {
dbUtil.close(conn, pstm, rs);
}
return u;
}
public String logout() {
return null;
}
/**
* 管理员记录数
* @param currentuser
* @return
*/
public int getTotal(User currentuser, String s_username) {
int total = 0;
Connection conn = dbUtil.getConnection();
StringBuffer sb = new StringBuffer("SELECT COUNT(*) AS total FROM t_user");
if(currentuser != null && StringUtil.isNotEmpty(s_username)) {
sb.append(" AND username LIKE '%"+ s_username +"%'");
}
sb.append(" WHERE id != ?");
String sql = sb.toString().replaceFirst("AND", "WHERE");
@SuppressWarnings("serial")
public class GoodsAction extends ActionSupport{
private String page; // 第几页
private String rows; // 每页记录数
private String s_goodsname = ""; // 搜索商品名
private String s_supplier = ""; // 搜索供应商
private String s_type = ""; // 搜索商品类型
private Goods goods; // 商品
private String delIds; // 批量删除ID号
private String goodsid; // 商品ID
DBUtil dbUtil = new DBUtil();
GoodsService goodsService = new GoodsService();
public String execute() throws Exception{
PageBean pageBean = new PageBean(Integer.parseInt(page), Integer.parseInt(rows));
Connection conn = dbUtil.getConnection();
if (goods == null) {
goods = new Goods();
}
if(StringUtil.isNotEmpty(s_goodsname)){
goods.setGoodsname(s_goodsname);
}
if(StringUtil.isNotEmpty(s_supplier)){
goods.setSupplier(s_supplier);
}
if(StringUtil.isNotEmpty(s_type)){
goods.setType(s_type);
}
int total = goodsService.goodsListTotal(goods,conn);
JSONObject result = new JSONObject();
JSONArray jsonArray = null;
try {
jsonArray = JsonUtil.formatRsToJsonArray(goodsService.goodsList(pageBean, goods,conn)); // 将结果集转为json数组
result.put("rows", jsonArray);
result.put("total", total);
ResponseUtil.write(ServletActionContext.getResponse(), result);
} catch (Exception e) {
e.printStackTrace();
throw e;