河北金力集团公文流转系统

1、项目需求:

河北金力集团是我省机械加工的龙头企业,主要从事矿山机械制造及各种机械零部件加工。企业有3个厂区,主厂区位于省高新技术开发区,3个分厂分别在保定、邢台和唐山。为增加企业的核心竞争力和加强管理的科学程度,近期企业将在全集团实行ERP管理,建立网页版公文流转系统。具体部门:主厂区、一分厂、二分厂、三分厂、销售部门、财务部门、办公室;领导:三位副厂长(分别管理生产、销售、财务)、一位厂长。

公文流转的流程:

2. 板块功能需求

(1)、页面要求

① 能适应800*600或1024*768分辨率;

② 布局合理、结构清晰、页面完整;

③ 有效页面数在8页以上;

④ 分页与主页风格统一;

⑤ 首页(登录页):用户登录页(共有十位用户帐号,帐号、密码可预设)。不同用户登录后,进入的功能页不相同,要求密码在数据库中加密。

⑥ 部门(不含办公室)功能页:有公文拟制、签收公文、浏览公文(已签收的公文)三个模块

⑦ 办公室功能页:有修改公文、公文流转、删除公文、公文发送等功能。

⑧ 副厂长功能页:有审核公文(修改并签意见)、浏览已发所有公文、查询公文三个模块。

⑨ 厂长功能页:有审签公文(修改并签意见)、浏览已发所有公文、查询公文三个模块。

⑩ 系统管理功能页:有用户管理、角色管理、公文流转流程管理。

(2)、功能设计:

  1. 公文拟制:创建新的电子公文,对创建的电子公文进行上传操作。
  2. 签收公文:当接收方接收公文后,会给发送方发回执信息,确认公文已经收到。
  3. 浏览公文(已签收的公文):

1) 选择日期段。

2) 通过“查询”功能,显示该时间段内已通过审签的正式公文。

3) 点击公文标题,将会显示出该公文的具体信息。

  1. 修改公文:对拟制好的的电子公文进行格式化处理操作,套用公文样例。
  2. 公文流转:按照公文流转流程设定公文接收用户。
  3. 删除公文:如果该公文没有通过审核或审签,需要删除可以利用“删除”功能。确定后,系统提示公文删除成功,删除的公文将在“被删除公文”模块中的显示。
  4. 公文发送:操作员要根据单位管理员选择的公文的流程进行公文的流转发送,实现待发公文和已发送公文的管理
  5. 审核公文(修改并签意见):签署审核意见和修改意见,并将退回办公室。
  6. 有审签公文(修改并签意见):签署审前意见和修改意见,若同意,则生成正式公文并交由办公室转发。
  7. 浏览已发所有公文:按日期查看所有已发公文,点击标题可查看具体信息。
  8. 公文查询:是查询由公文交换系统处理过的公文,并且建立或检查公文详尽的索引信息。可以根据发送机构、接收机构、公文种类和其它开放信息进行公文数据查询。
  9. 系统管理:

a)  角色配置管理

  1. 用户权限维护功能:实现对用户的角色管理。
  2. 角色维护功能:实现对角色权限的管理,主要有编辑、增加和删除操作。

b) 用户管理:查看用户、新开用户、暂停用户、用户信息修改、删除用户

c) 单位管理员设置功能:每个单位的操作员实现修改密码、修改个人信息。

(3). 公文样例

完成情况:完成了表的构建,bean层, dao层,util、sevlet层刚开始,主页面完成剩下页面没有完成

代码如下:

bean层:

公文信息类

package bean;

public class InfoBean {
private int id;
private String title;
private String owner;
private String time;
private String receiver;
private int status;
private int result;
private String place;
private String viceplace;
private String primaryplace;
private int deletestatus;
private int callback; public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} public String getOwner() {
return owner;
} public void setOwner(String owner) {
this.owner = owner;
} public String getTime() {
return time;
} public void setTime(String time) {
this.time = time;
} public String getReceiver() {
return receiver;
} public void setReceiver(String receiver) {
this.receiver = receiver;
} public int getStatus() {
return status;
} public void setStatus(int status) {
this.status = status;
} public int getResult() {
return result;
} public void setResult(int result) {
this.result = result;
} public String getPlace() {
return place;
} public void setPlace(String place) {
this.place = place;
} public String getViceplace() {
return viceplace;
} public void setViceplace(String viceplace) {
this.viceplace = viceplace;
} public String getPrimaryplace() {
return primaryplace;
} public void setPrimaryplace(String primaryplace) {
this.primaryplace = primaryplace;
} public int getDeletestatus() {
return deletestatus;
} public void setDeletestatus(int deletestatus) {
this.deletestatus = deletestatus;
} public int getCallback() {
return callback;
} public void setCallback(int callback) {
this.callback = callback;
} public InfoBean(int id, String title, String owner, String time, String receiver, int status, int result,
String place, String viceplace, String primaryplace, int deletestatus, int callback) {
super();
this.id = id;
this.title = title;
this.owner = owner;
this.time = time;
this.receiver = receiver;
this.status = status;
this.result = result;
this.place = place;
this.viceplace = viceplace;
this.primaryplace = primaryplace;
this.deletestatus = deletestatus;
this.callback = callback;
} public InfoBean() {
// TODO Auto-generated constructor stub
} }

权限

package bean;

public class authority {
private int id;
private int authority;; public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public int getAuthority() {
return authority;
} public void setAuthority(int authority) {
this.authority = authority;
} public authority() {
// TODO Auto-generated constructor stub
} }

user类:

package bean;

public class user {
private int id;
private String username;
private String password;
private int permissionId;
private int status;
private String job; public String getJob() {
return job;
} public void setJob(String job) {
this.job = job;
} public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public int getPermissionId() {
return permissionId;
} public void setPermissionId(int permissionId) {
this.permissionId = permissionId;
} public int getStatus() {
return status;
} public void setStatus(int status) {
this.status = status;
} public user() {
// TODO Auto-generated constructor stub
} }

dao层,对于每个功能的实现:

package dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import bean.InfoBean;
import bean.authority;
import bean.user;
import util.DBUtil; public class dao {
public static ArrayList<InfoBean> getInfos(String str) {
Connection conn = null;
PreparedStatement pst = null;
ResultSet rs = null;
conn = DBUtil.getConnection();
String sql;
if (str.equals("receive"))
sql = "select * from infobean where status=0 or status=2 or status=3 or status=4 or status=5 or status=6 or status=7 or status=-1 and deletestatus=0";
if (str.equals("send"))
sql = "select * from infobean where status=1 or status=4 or status=5 or status=8 or status=9 or status=10 and deletestatus=0";
if (str.equals("delete"))
sql = "select * from infobean where deletestatus=1";
else
sql = "select * from infobean";
try { PreparedStatement prepareStatement = conn.prepareStatement(sql);
rs = prepareStatement.executeQuery();
ArrayList<InfoBean> list = new ArrayList<>();
while (rs.next()) {
InfoBean ib = new InfoBean();
ib.setId(rs.getInt("id"));
ib.setTitle(rs.getString("title"));
ib.setOwner(rs.getString("owner"));
ib.setTime(rs.getString("time"));
ib.setReceiver(rs.getString("receive"));
ib.setStatus(rs.getInt("status"));
ib.setResult(rs.getInt("reslut"));
ib.setPlace(rs.getString("place"));
ib.setDeletestatus(rs.getInt("deletestatus"));
list.add(ib); }
return list;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DBUtil.close(rs, pst, conn);
}
return null;
} public static boolean userExits(user user) {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
con = DBUtil.getConnection();
String sql = "select * from user where username ='" + user.getUsername() + "'and password='"
+ user.getPassword() + "'and status !=0";
try {
pstmt = con.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next() == false)
return false;
else
return true;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, con);
}
return false;
} public static boolean addInfo(InfoBean ib) {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DBUtil.getConnection();
String sql = "insert into infobean(title,owner,receiver,time,status,result,place,deletestatus,callback) values(?,?,?,?,?,?,?,?,?)";
pstmt = con.prepareStatement(sql);
pstmt.setString(1, ib.getTitle());
pstmt.setString(2, ib.getOwner());
pstmt.setString(3, ib.getReceiver());
pstmt.setString(4, ib.getTime());
pstmt.setInt(5, ib.getStatus());
pstmt.setInt(6, ib.getResult());
pstmt.setString(7, ib.getPlace());
pstmt.setInt(8, 0);
pstmt.setInt(9, 0);
pstmt.executeUpdate();
return true;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, pstmt, con);
}
return false; } public static boolean delete_user(user u) {
Connection con = null;
PreparedStatement pstmt = null; try {
con = DBUtil.getConnection();
String sql = "delete from user where id=" + u.getId();
System.out.println(sql);
pstmt = con.prepareStatement(sql);
pstmt.executeUpdate();
return true;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, con);
}
return false;
} public static boolean update_user_status(user user) {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DBUtil.getConnection();
String sql = "update user set status = ? where id = ?";
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, user.getStatus());
pstmt.setInt(2, user.getId());
pstmt.executeUpdate();
return true;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, con);
}
return false;
} public static boolean update_user(user user) {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DBUtil.getConnection();
String sql = "update user set username=?,password=?,job=? where id = " + user.getId();
pstmt = con.prepareStatement(sql);
pstmt.setString(1, user.getUsername());
pstmt.setString(2, user.getPassword());
pstmt.setString(3, user.getJob());
pstmt.executeUpdate();
return true;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, con);
}
return false;
} @SuppressWarnings("resource")
public static boolean sendDoc(int id) {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int status = -1;
int newstatus = -1;
String receiver = "";
try {
con = DBUtil.getConnection();
String sql = "select * from infobean where id=" + id;
pstmt = con.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next()) {
status = rs.getInt("status");
}
switch (status) {
case 0:
newstatus = 1;
receiver = "副厂长";
break;
case 2:
newstatus = 5;
receiver = "厂长";
break;
case 3:
newstatus = 4;
receiver = "部门";
break;
case 6:
newstatus = 8;
receiver = "部门和副厂长";
break;
case 7:
newstatus = 9;
receiver = "部门和副厂长";
break;
case 8:
newstatus = 10;
receiver = "部门";
break;
default:
System.out.println("公文状态有误!");
break;
}
String sql_update = "update infobean set status = ? where id = ?";
pstmt = con.prepareStatement(sql_update);
pstmt.setInt(1, newstatus);
pstmt.setInt(2, id);
pstmt.executeUpdate();
return true;
} catch (SQLException e) {
System.out.println("数据库信息更新失败");
e.printStackTrace();
} finally {
DBUtil.close(pstmt, con);
}
return false;
} public static ArrayList<InfoBean> getInfoBychoose(String type, String value) {
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet rs = null;
try {
connection = DBUtil.getConnection();
String sql = "";
System.out.println(type);
if (type.equals("title")) {
sql = "select * from infobean where title='" + value + "'";
} else if (type.equals("owner")) {
sql = "select * from infobean where owner='" + value + "'";
} else if (type.equals("receiver")) {
sql = "select * from infobean where receiver='" + value + "'";
} else if (type.equals("result")) {
sql = "select * from infobean where result='" + value + "'";
}
preparedStatement = connection.prepareStatement(sql);
rs = preparedStatement.executeQuery();
ArrayList<InfoBean> list = new ArrayList<>();
while (rs.next()) {
InfoBean ib = new InfoBean();
ib.setId(rs.getInt("id"));
ib.setTitle(rs.getString("title"));
ib.setOwner(rs.getString("owner"));
ib.setTime(rs.getString("time"));
ib.setReceiver(rs.getString("receiver"));
ib.setStatus(rs.getInt("status"));
ib.setResult(rs.getInt("result"));
ib.setPlace(rs.getString("place"));
list.add(ib);
}
return list;
} catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
} finally {
DBUtil.close(rs, preparedStatement, connection);
}
return null;
} public static ArrayList<InfoBean> getCheckedOrNotInfo(String type) {
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet rs = null;
try {
connection = DBUtil.getConnection();
String sql = "";
if (type.equals("checked")) {
sql = "select * from infobean where status=6 or status=7";
} else {
sql = "select * from infobean where status=5";
}
preparedStatement = connection.prepareStatement(sql);
rs = preparedStatement.executeQuery();
ArrayList<InfoBean> list = new ArrayList<>();
while (rs.next()) {
InfoBean ib = new InfoBean();
ib.setId(rs.getInt("id"));
ib.setTitle(rs.getString("title"));
ib.setOwner(rs.getString("owner"));
ib.setTime(rs.getString("time"));
ib.setReceiver(rs.getString("receiver"));
ib.setStatus(rs.getInt("status"));
ib.setResult(rs.getInt("result"));
ib.setPlace(rs.getString("place"));
list.add(ib);
}
return list;
} catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
} finally {
DBUtil.close(rs, preparedStatement, connection);
}
return null;
} public static ArrayList<InfoBean> getCheckedorNot(String str) {
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet rs = null;
try {
connection = DBUtil.getConnection();
String sql = "";
System.out.println(str);
if (str.equals("notchecked")) {
sql = "select * from infobean where status=1";
} else {
sql = "select * from infobean where status!=1 and status!=0 and status!=-1";
}
preparedStatement = connection.prepareStatement(sql);
rs = preparedStatement.executeQuery();
ArrayList<InfoBean> list = new ArrayList<>();
while (rs.next()) {
InfoBean ib = new InfoBean();
ib.setId(rs.getInt("id"));
ib.setTitle(rs.getString("title"));
ib.setOwner(rs.getString("owner"));
ib.setTime(rs.getString("time"));
ib.setReceiver(rs.getString("receiver"));
ib.setStatus(rs.getInt("status"));
ib.setResult(rs.getInt("result"));
ib.setPlace(rs.getString("place"));
list.add(ib);
}
return list;
} catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
} finally {
DBUtil.close(rs, preparedStatement, connection);
}
return null;
} public static ArrayList<InfoBean> getReceivedInfoByUser(String type, user user) {
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet rs = null;
try {
connection = DBUtil.getConnection();
String sql = "";
if (type.equals("received")) {
sql = "select * from infobean where owner=? and status=10";
} else {
sql = "select * from infobean where owner=? and status!=10";
}
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, user.getUsername());
rs = preparedStatement.executeQuery();
ArrayList<InfoBean> list = new ArrayList<>();
while (rs.next()) {
InfoBean doc = new InfoBean();
doc.setId(rs.getInt("id"));
doc.setTitle(rs.getString("title"));
doc.setTime(rs.getString("time"));
doc.setStatus(rs.getInt("status"));
doc.setResult(rs.getInt("result"));
list.add(doc);
}
return list;
} catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
} finally {
DBUtil.close(rs, preparedStatement, connection);
}
return null;
} public static InfoBean getInfoById(InfoBean ib) {
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet rs = null;
try {
connection = DBUtil.getConnection();
String sql = "select * from infobean where id=" + ib.getId();
preparedStatement = connection.prepareStatement(sql);
rs = preparedStatement.executeQuery();
if (rs.next()) {
ib.setTitle(rs.getString("title"));
ib.setOwner(rs.getString("owner"));
ib.setTime(rs.getString("time"));
ib.setReceiver(rs.getString("receiver"));
ib.setStatus(rs.getInt("status"));
ib.setResult(rs.getInt("result"));
ib.setPlace(rs.getString("place"));
ib.setViceplace(rs.getString("viceplace"));
ib.setPrimaryplace(rs.getString("primaryplace"));
return ib;
}
} catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
} finally {
DBUtil.close(rs, preparedStatement, connection);
}
return null;
} public static boolean checked_change(InfoBean ib) {
Connection connection = null;
PreparedStatement preparedStatement = null;
String sql = "update infobean set status = ?,result = ?,receiver = ?,viceplace = ? where id = ?";
try {
connection = DBUtil.getConnection();
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1, ib.getStatus());
preparedStatement.setInt(2, ib.getResult());
preparedStatement.setString(3, ib.getReceiver());
preparedStatement.setString(4, ib.getViceplace());
preparedStatement.setInt(5, ib.getId());
preparedStatement.executeUpdate();
return true;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(preparedStatement, connection);
}
return false;
} public static boolean unchecked_change(InfoBean ib) {
Connection connection = null;
PreparedStatement preparedStatement = null;
String sql = "update infobean set status = ?,result = ?,receiver = ?,viceplace = ? where id = ?";
try {
connection = DBUtil.getConnection();
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1, ib.getStatus());
preparedStatement.setInt(2, ib.getResult());
preparedStatement.setString(3, ib.getReceiver());
preparedStatement.setString(4, ib.getViceplace());
preparedStatement.setInt(5, ib.getId());
preparedStatement.executeUpdate();
return true;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(preparedStatement, connection);
}
return false;
} public static boolean formatDoc(InfoBean ib) {
Connection connection = null;
PreparedStatement preparedStatement = null;
String sql_update = "update infobean set status = ? where id = ?";
try {
connection = DBUtil.getConnection();
preparedStatement = connection.prepareStatement(sql_update);
preparedStatement.setInt(1, ib.getStatus());
preparedStatement.setInt(2, ib.getId());
preparedStatement.executeUpdate();
return true;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(preparedStatement, connection);
}
return false;
} public static boolean ReceiveInfo(InfoBean ib) {
Connection connection = null;
PreparedStatement preparedStatement = null;
String sql = "update infobean set status = ?,callback = 1 where id = ?";
try {
connection = DBUtil.getConnection();
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1, 10);
preparedStatement.setInt(2, ib.getId());
preparedStatement.executeUpdate();
return true;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(preparedStatement, connection);
}
return false;
} public static ArrayList<InfoBean> getInfoByTime(InfoBean ib1, InfoBean ib2) {
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet rs = null;
String sql = "select * from infobean where time between ? and ?";
try {
connection = DBUtil.getConnection();
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, ib1.getTime());
preparedStatement.setString(2, ib2.getTime());
rs = preparedStatement.executeQuery();
ArrayList<InfoBean> list = new ArrayList<>();
while (rs.next()) {
InfoBean doc = new InfoBean();
doc.setId(rs.getInt("id"));
doc.setTitle(rs.getString("title"));
doc.setTime(rs.getString("time"));
doc.setOwner(rs.getString("owner"));
list.add(doc);
}
return list;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, preparedStatement, connection);
}
return null;
} public static ArrayList<InfoBean> getAllInfos() {
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet rs = null;
String sql = "select * from infobean";
try {
connection = DBUtil.getConnection();
preparedStatement = connection.prepareStatement(sql);
rs = preparedStatement.executeQuery();
ArrayList<InfoBean> list = new ArrayList<>();
while (rs.next()) {
InfoBean ib = new InfoBean();
ib.setId(rs.getInt("id"));
ib.setTitle(rs.getString("title"));
ib.setTime(rs.getString("time"));
ib.setOwner(rs.getString("owner"));
list.add(ib);
}
return list;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, preparedStatement, connection);
}
return null;
} public static ArrayList<user> getAllUser() {
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet rs = null;
String sql = "select * from user";
try {
connection = DBUtil.getConnection();
preparedStatement = connection.prepareStatement(sql);
rs = preparedStatement.executeQuery();
ArrayList<user> list = new ArrayList<>();
while (rs.next()) {
user user = new user();
user.setId(rs.getInt("id"));
user.setUsername(rs.getString("username"));
user.setPassword(rs.getString("password"));
user.setPermissionId(rs.getInt("permissionId"));
user.setJob(rs.getString("job"));
user.setStatus(rs.getInt("status"));
list.add(user);
}
return list;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, preparedStatement, connection);
}
return null;
} public static user getUserById(user user) {
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet rs = null;
String sql = "select * from user where id=" + user.getId();
try {
connection = DBUtil.getConnection();
preparedStatement = connection.prepareStatement(sql);
rs = preparedStatement.executeQuery();
user user1 = new user();
if (rs.next()) {
user1.setId(rs.getInt("id"));
user1.setUsername(rs.getString("username"));
user1.setPassword(rs.getString("password"));
user1.setPermissionId(rs.getInt("permissionId"));
user1.setStatus(rs.getInt("status"));
user1.setJob(rs.getString("job"));
}
return user1;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(preparedStatement, connection);
}
return null;
} public static ArrayList<authority> getAuthority(authority at) {
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet rs = null;
String sql = "select * from permission where id=" + at.getId();
try {
connection = DBUtil.getConnection();
preparedStatement = connection.prepareStatement(sql);
rs = preparedStatement.executeQuery();
ArrayList<authority> list = new ArrayList<>();
while (rs.next()) {
authority at1 = new authority();
at1.setId(rs.getInt("id"));
at1.setAuthority(rs.getInt("authority"));
list.add(at1);
}
return list;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, preparedStatement, connection);
}
return null;
} public static boolean deleteAuthority(authority at) {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DBUtil.getConnection();
String sql = "delete from permission where id=" + at.getId();
pstmt = con.prepareStatement(sql);
pstmt.executeUpdate();
return true;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, con);
}
return false;
} public static boolean updateAuthority(authority at1, authority at2) {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DBUtil.getConnection();
String sql = "update permission set permission = ? where id = ? and permission = ?";
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, at2.getAuthority());
pstmt.setInt(2, at1.getId());
pstmt.setInt(3, at1.getAuthority());
pstmt.executeUpdate();
return true;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, con);
}
return false;
} public dao() {
// TODO Auto-generated constructor stub
} public static boolean updatePwd(user user) {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DBUtil.getConnection();
String sql = "update users set password = ? where username = ?";
pstmt = con.prepareStatement(sql);
pstmt.setString(1, user.getPassword());
pstmt.setString(2, user.getUsername());
pstmt.executeUpdate();
return true;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, con);
}
return false;
} public static user getUserByUsername(user user) {
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet rs = null;
String sql = "select * from user where username='" + user.getUsername() + "'";
try {
connection = DBUtil.getConnection();
preparedStatement = connection.prepareStatement(sql);
rs = preparedStatement.executeQuery();
user user1 = new user();
if (rs.next()) {
user1.setId(rs.getInt("id"));
user1.setPermissionId(rs.getInt("permissionId"));
System.out.println(user1.getPermissionId());
}
return user1;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, preparedStatement, connection);
}
return null;
} public static boolean deleteInfo(InfoBean ib) {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DBUtil.getConnection();
String sql = "update infobean set deletestatus = ? where id = ?";
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, ib.getDeletestatus());
pstmt.setInt(2, ib.getId());
pstmt.executeUpdate();
return true;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, con);
}
return false;
} public static ArrayList<InfoBean> getCall() {
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet rs = null;
try {
connection = DBUtil.getConnection();
String sql = "select * from infobean where callback=1";
preparedStatement = connection.prepareStatement(sql);
rs = preparedStatement.executeQuery();
ArrayList<InfoBean> list = new ArrayList<>();
while (rs.next()) {
InfoBean ib = new InfoBean();
ib.setId(rs.getInt("id"));
ib.setTitle(rs.getString("title"));
ib.setOwner(rs.getString("owner"));
ib.setTime(rs.getString("time"));
ib.setReceiver(rs.getString("receiver"));
ib.setStatus(rs.getInt("status"));
ib.setResult(rs.getInt("result"));
ib.setPlace(rs.getString("place"));
ib.setDeletestatus(rs.getInt("deletestatus"));
ib.setCallback(rs.getInt("callback"));
list.add(ib);
}
return list;
} catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
} finally {
DBUtil.close(rs, preparedStatement, connection);
}
return null;
} public static boolean setCallOver(InfoBean ib) {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DBUtil.getConnection();
String sql = "update infobean set callback = ? where id = ?";
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, 0);
pstmt.setInt(2, ib.getId());
pstmt.executeUpdate();
return true;
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(pstmt, con);
}
return false;
} }

DBUtil对于数据库的操作封装:

package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement; public class DBUtil {
private static String url = "jdbc:mysql://localhost:3306/doc_system?useUnicode=true&characterEncoding=utf8";
private static String user = "root";
private static String password = "root";
private static String jdbcName="com.mysql.jdbc.Driver";
private Connection con=null;
public static Connection getConnection() {
Connection con=null;
try {
Class.forName(jdbcName);
con=DriverManager.getConnection(url, user, password);
System.out.println("数据库连接成功");
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("数据库连接失败");
e.printStackTrace();
}
return con; }
public static void close(Connection con) {
if(con!=null)
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
public static void close(Statement state, Connection conn) {
if(state!=null) {
try {
state.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(conn!=null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
} public static void close(ResultSet rs, Statement state, Connection conn) {
if(rs!=null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(state!=null) {
try {
state.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(conn!=null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}

servlet对于公文的接受:

package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import bean.InfoBean;
import dao.dao; /**
* Servlet implementation class receive
*/
@WebServlet("/receive")
public class receive extends HttpServlet {
private static final long serialVersionUID = 1L; /**
* @see HttpServlet#HttpServlet()
*/
public receive() {
super();
// TODO Auto-generated constructor stub
} /**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
int id=Integer.parseInt(request.getParameter("id"));
InfoBean ib=new InfoBean();
ib.setId(id);
if(dao.setCallOver(ib)) response.getWriter().write("yes");
else response.getWriter().write("no");
} /**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
} }

其他的servlet还没写完

表结构:

其他页面尚未完成

体会:当遇到很多很多的代码的时候发现了封装成类有多么简便 ,这样频繁的调用要比写要简单的多。这种大项目主要是业务流程的分析,只有清楚每个流程,分析到位,你才能知道这些到底应该怎么做,应该怎么封装。但是dao层的任务量实在是太大了 有两小时在写dao层,别的更没有时间。因此还要加强增删改查的基本操作,越来越熟悉,写的速度也越快,只有这样才能在规定的时间内完成任务。另外在自己编程的过程中要总结方法,总结到底怎么做才能简化代码量,提高自己的效率。老师一让计时,这才发现自己写代码速度到底有多慢,因此还需要加强自己的薄弱项目。重在实践,多动手。多分析业务流程,对业务流程在脑中有一个清楚的认识,这样才能快速的编程。而且拿到题目的时候,不是直接去写,而是去分析流程,分析结构,分析自己应该用什么方法,怎么做。每次做题的时候都要去分析。你写出正确的代码的前提是你了解业务流程。这样写起代码来才会得心应手。要寻找一些方法中的共同点,然后简化代码。

最新文章

  1. Tornado 学习笔记13 TCPServer
  2. centos5.11 repo 安装mysql5.7
  3. 对于System.Net.Http的学习(一)——System.Net.Http 简介
  4. git之三
  5. DRAM 内存介绍(三)
  6. Visual Studio 2012 怪异的自动重启
  7. NYOJ214
  8. python 从private key pem文件中加载public key
  9. ios游戏开发--cocos2d学习(2)
  10. 【Java】WEB-INF目录与META-INF目录的作用
  11. 四、Mp3文件类型及其判断
  12. Chapter 20_1 table库
  13. Vue过渡效果之CSS过渡
  14. JSP、HTML页面概述
  15. VS2010+WPF+LINQ for MySQL
  16. Androi开发 ---Fragment片段布局案例
  17. MVC3学习:利用mvc3+ajax实现全选和批量删除
  18. [2016北京集训测试赛15]statement-[线段树+拆环]
  19. Keepalived + Nginx + Tomcat 的高可用负载均衡架构搭建
  20. [HTML5] Canvas绘制简单形状

热门文章

  1. hdu 4632区间dp 回文字串计数问题
  2. [js]EasyUI导出数据表格(Export DataGrid)
  3. spring-test跟junit结合单元测试获取ApplicationContext实例的方法
  4. maven简识
  5. java实现spark常用算子之Union
  6. [Android] Installation failed due to: &#39;&#39;pm install-create -r -t -S 4590498&#39; returns error &#39;UNSUPPORTED&#39;&#39;
  7. 【ExtJs】在Ext.grid.Panel中,两列的值相乘作为第三列的值的实现
  8. vue实现吸顶
  9. TensorFlow中CNN的两种padding方式“SAME”和“VALID”
  10. java9 新特征