帮我写《建设工程监管信息系统》交易流程步骤列表显示模块代码
时间: 2024-01-19 22:02:49 浏览: 102
好的,下面是《建设工程监管信息系统》交易流程步骤列表显示模块的代码示例。为了简化代码,这里将只列出关键部分,具体实现可以根据实际需求进行修改:
1. FlowStepBean.java
```java
package com.construction.monitor.bean;
public class FlowStepBean {
private int id;
private String name;
private String description;
private String createTime;
private String updateTime;
// getter and setter methods
}
```
2. FlowStepDAO.java
```java
package com.construction.monitor.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.construction.monitor.bean.FlowStepBean;
import com.construction.monitor.util.DBUtil;
public class FlowStepDAO {
private Connection conn = null;
private PreparedStatement pstmt = null;
private ResultSet rs = null;
// 添加交易流程步骤
public boolean addFlowStep(FlowStepBean flowStep) {
boolean flag = false;
String sql = "INSERT INTO T_flow_step_def(name, description, create_time, update_time) VALUES(?, ?, ?, ?)";
try {
conn = DBUtil.getConnection();
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, flowStep.getName());
pstmt.setString(2, flowStep.getDescription());
pstmt.setString(3, flowStep.getCreateTime());
pstmt.setString(4, flowStep.getUpdateTime());
int result = pstmt.executeUpdate();
if(result > 0) {
flag = true;
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.closeAll(rs, pstmt, conn);
}
return flag;
}
// 删除交易流程步骤
public boolean deleteFlowStep(int id) {
boolean flag = false;
String sql = "DELETE FROM T_flow_step_def WHERE id = ?";
try {
conn = DBUtil.getConnection();
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, id);
int result = pstmt.executeUpdate();
if(result > 0) {
flag = true;
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.closeAll(rs, pstmt, conn);
}
return flag;
}
// 修改交易流程步骤
public boolean updateFlowStep(FlowStepBean flowStep) {
boolean flag = false;
String sql = "UPDATE T_flow_step_def SET name = ?, description = ?, update_time = ? WHERE id = ?";
try {
conn = DBUtil.getConnection();
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, flowStep.getName());
pstmt.setString(2, flowStep.getDescription());
pstmt.setString(3, flowStep.getUpdateTime());
pstmt.setInt(4, flowStep.getId());
int result = pstmt.executeUpdate();
if(result > 0) {
flag = true;
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.closeAll(rs, pstmt, conn);
}
return flag;
}
// 查询所有交易流程步骤
public List<FlowStepBean> getFlowStepList() {
List<FlowStepBean> list = new ArrayList<FlowStepBean>();
String sql = "SELECT id, name, description, create_time, update_time FROM T_flow_step_def";
try {
conn = DBUtil.getConnection();
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()) {
FlowStepBean flowStep = new FlowStepBean();
flowStep.setId(rs.getInt("id"));
flowStep.setName(rs.getString("name"));
flowStep.setDescription(rs.getString("description"));
flowStep.setCreateTime(rs.getString("create_time"));
flowStep.setUpdateTime(rs.getString("update_time"));
list.add(flowStep);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.closeAll(rs, pstmt, conn);
}
return list;
}
}
```
3. FlowStepServlet.java
```java
package com.construction.monitor.servlet;
import java.io.IOException;
import java.util.List;
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 com.construction.monitor.bean.FlowStepBean;
import com.construction.monitor.dao.FlowStepDAO;
@WebServlet("/flowStepServlet")
public class FlowStepServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String action = request.getParameter("action");
FlowStepDAO flowStepDAO = new FlowStepDAO();
// 添加交易流程步骤
if("add".equals(action)) {
String name = request.getParameter("name");
String description = request.getParameter("description");
FlowStepBean flowStep = new FlowStepBean();
flowStep.setName(name);
flowStep.setDescription(description);
flowStep.setCreateTime(System.currentTimeMillis() + "");
flowStep.setUpdateTime(flowStep.getCreateTime());
if(flowStepDAO.addFlowStep(flowStep)) {
response.sendRedirect("flow_step_list.jsp");
} else {
response.sendRedirect("error.jsp");
}
}
// 删除交易流程步骤
if("delete".equals(action)) {
int id = Integer.parseInt(request.getParameter("id"));
if(flowStepDAO.deleteFlowStep(id)) {
response.sendRedirect("flow_step_list.jsp");
} else {
response.sendRedirect("error.jsp");
}
}
// 修改交易流程步骤
if("update".equals(action)) {
int id = Integer.parseInt(request.getParameter("id"));
String name = request.getParameter("name");
String description = request.getParameter("description");
FlowStepBean flowStep = new FlowStepBean();
flowStep.setId(id);
flowStep.setName(name);
flowStep.setDescription(description);
flowStep.setUpdateTime(System.currentTimeMillis() + "");
if(flowStepDAO.updateFlowStep(flowStep)) {
response.sendRedirect("flow_step_list.jsp");
} else {
response.sendRedirect("error.jsp");
}
}
// 查询所有交易流程步骤
if("list".equals(action)) {
List<FlowStepBean> list = flowStepDAO.getFlowStepList();
request.setAttribute("list", list);
request.getRequestDispatcher("flow_step_list.jsp").forward(request, response);
}
}
}
```
4. flow_step_list.jsp
```html
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>交易流程步骤列表</title>
</head>
<body>
<h1>交易流程步骤列表</h1>
<table border="1">
<tr>
<th>编号</th>
<th>名称</th>
<th>描述</th>
<th>创建时间</th>
<th>修改时间</th>
<th>操作</th>
</tr>
<c:forEach var="flowStep" items="${list}">
<tr>
<td>${flowStep.id}</td>
<td>${flowStep.name}</td>
<td>${flowStep.description}</td>
<td>${flowStep.createTime}</td>
<td>${flowStep.updateTime}</td>
<td>
<a href="flowStepServlet?action=delete&id=${flowStep.id}">删除</a>
<a href="flow_step_edit.jsp?id=${flowStep.id}&name=${flowStep.name}&description=${flowStep.description}">修改</a>
</td>
</tr>
</c:forEach>
</table>
<a href="flow_step_add.jsp">添加交易流程步骤</a>
</body>
</html>
```
通过以上代码示例,可以实现对交易流程步骤的增加、删除、修改和查询等操作,并在flow_step_list.jsp页面中显示交易流程步骤的列表信息。
阅读全文