团队作业(五):冲刺总结2
项目名:电子公文传输系统
成员分工:熊悠越(前端开发)、罗杰逊+谷丰宇(后端开发)、陈夏林(数据库管理)、董准(系统测试与维护)
日期:2023.12.08
今日任务完成情况
前端
前端部分代码
<!DOCTYPE html>
<html>
<head>
<title>Login Page</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="login-container">
<h2>Login</h2>
<form action="/login" method="post">
<div class="form-group">
<label for="username">Username:</label>
<input type="text" id="username" name="username">
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" id="password" name="password">
</div>
<button type="submit">Login</button>
<a href="register.html">Register</a>
</form>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>File Management</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="file-container">
<h2>File Management</h2>
<!-- 文件列表 -->
<table>
<tr>
<th>File Name</th>
<th>Actions</th>
</tr>
<!-- Example File Row -->
<tr>
<td>example.txt</td>
<td>
<button>Download</button>
<button>Delete</button>
</td>
</tr>
<!-- More files can be listed here -->
</table>
</div>
</body>
</html>
后端
登录
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JRadioButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
public class Login extends JFrame implements ActionListener
{
private JPasswordField mima1 = new JPasswordField(30); // 创建文本行组件, 30 列
private JTextField zh1 = new JTextField(30);
private JButton dl1 = new JButton("登陆");
private JButton zb1 = new JButton("注册账号");
private JLabel zh2 = new JLabel("账号:");
private JLabel mima2 = new JLabel("密码:");
BackgroundPanel bgp;
JFrame f;
String st5 = "1";
String st6 = "0";
public Login()
{
f = new JFrame("登陆界面");
f.setBounds(200, 150, 555, 420);
f.setLayout(null);
bgp=new BackgroundPanel((new ImageIcon("C:\\Users\\14914\\Desktop\\图片中转站\\背景\\2.jpg")).getImage());
bgp.setBounds(0,0,555,188);
zh1.setBounds(120, 190, 300, 40);
mima1.setBounds(120, 238, 300, 40);
dl1.setBounds(120, 300, 300, 46);
zh2.setBounds(70, 190, 50, 40);
zb1.setBounds(0, 350, 90, 25);
mima2.setBounds(70, 238, 50, 40);
// 把组件添加进窗口f中
f.add(mima1);
f.add(zh1);
f.add(dl1);
f.add(zb1);
f.add(zh2);
f.add(mima2);
f.add(bgp);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
KeyListener key_Listener = new KeyListener()
{
public void keyTyped(KeyEvent e) {}
public void keyReleased(KeyEvent e){}
public void keyPressed(KeyEvent e){
if(e.getKeyChar() == KeyEvent.VK_ENTER )
{
PreparedStatement ps=null;
Connection ct=null;
ResultSet rs=null;
String st1 = "null";
{
try {
//1.加载驱动
Class.forName("com.mysql.cj.jdbc.Driver");
//2.得到链接 127.0.0.1:1433
ct=DriverManager.getConnection
("jdbc:mysql://127.0.0.1:3307/myfiletra?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2B8","root","123456");
String sql="select password from user where id = ?";
ps=ct.prepareStatement(sql);
//给?赋值
ps.setString(1, zh1.getText());
rs=ps.executeQuery();
while(rs.next()){
st1=rs.getString(1).trim();
}
}catch(Exception d) {
d.printStackTrace();
}finally {
try {
if(rs!=null)rs.close();
if(ps!=null)ps.close();
if(ct!=null)ct.close();
}catch(Exception d) {
d.printStackTrace();
}
}
if(st1.equals(String.valueOf(mima1.getPassword())))
{
f.setVisible(false);
JOptionPane.showMessageDialog(null, "登录成功,欢迎到来!");
//显示信息提示框
(new FileTree()).show(true);;
}
else
{
JOptionPane.showMessageDialog(null, "用户或密码错误!请从新登录!");
//显示信息提示框
zh1.setText("");
mima1.setText("");
}
}
}
}
};
mima1.addKeyListener(key_Listener);
dl1.addActionListener(this); //登录增加事件监听
this.pack(); //表示随着面板自动调整大小
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent q) //
{
if(q.getSource() == dl1) {
PreparedStatement ps = null;
Connection ct = null;
ResultSet rs = null;
String st1 = "null";
try {
//1.加载驱动
Class.forName("com.mysql.cj.jdbc.Driver");
//2.得到链接 127.0.0.1:1433
ct = DriverManager.getConnection
("jdbc:mysql://127.0.0.1:3307/myfiletra?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2B8","root","123456");
String sql = "select id from user where id = ?";
ps = ct.prepareStatement(sql);
//给?赋值
ps.setString(1, zh1.getText());
rs = ps.executeQuery();
while (rs.next()) {
st1 = rs.getString(1).trim();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (rs != null) rs.close();
if (ps != null) ps.close();
if (ct != null) ct.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if(st1.equals(String.valueOf(mima1.getPassword())))
{
f.setVisible(false);
JOptionPane.showMessageDialog(null, "登录成功,欢迎到来!");
//显示信息提示框
(new FileTree()).show(true);;
}
else
{
JOptionPane.showMessageDialog(null, "用户或密码错误!请从新登录!");
//显示信息提示框
zh1.setText("");
mima1.setText("");
}
}
}
public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
new Login();
}
}
与MySQL数据库交互,数据库连接信息包括URL、用户名和密码
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.JOptionPane;
public class PutinStorage {
// 得到数据库表数据
public static Vector getRows() {
String sql_url = "jdbc:mysql://127.0.0.1:3307/myfiletra?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2B8"; //数据库路径(一般都是这样写),test是数据库名称
String name = "root"; //用户名
String password = "123456"; //密码
Connection conn;
PreparedStatement preparedStatement = null;
Vector rows = null;
Vector columnHeads = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver"); //连接驱动
conn = DriverManager.getConnection(sql_url, name, password); //连接数据库
preparedStatement = conn.prepareStatement("select filename,filesize from file");
ResultSet result1 = preparedStatement.executeQuery();
rows = new Vector();
ResultSetMetaData rsmd = result1.getMetaData();
while (result1.next()) {
rows.addElement(getNextRow(result1, rsmd));
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("FAILED DRIVEN MYSQL");
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println("FAILED FAILED MYSQL");
e.printStackTrace();
}
return rows;
}
// 得到数据库表头
public static Vector getHead() {
String sql_url = "jdbc:mysql://127.0.0.1:3307/myfiletra?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2B8"; //数据库路径(一般都是这样写),test是数据库名称
String name = "root"; //用户名
String password = "123456"; //密码
Connection conn;
PreparedStatement preparedStatement = null;
Vector rows = null;
Vector columnHeads = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver"); //连接驱动
conn = DriverManager.getConnection(sql_url, name, password); //连接数据库
preparedStatement = conn.prepareStatement("select distinct filename,filesize from file");
ResultSet result1 = preparedStatement.executeQuery();
boolean moreRecords = result1.next();
if (!moreRecords)
JOptionPane.showMessageDialog(null, "NO RESULT");
columnHeads = new Vector();
ResultSetMetaData rsmd = result1.getMetaData();
for (int i = 1; i <= rsmd.getColumnCount(); i++)
columnHeads.addElement(rsmd.getColumnName(i));
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("FAILED DRIVEN MYSQL");
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println("FAILED OPEN MYSQL");
e.printStackTrace();
}
return columnHeads;
}
// 得到数据库中下一行数据
private static Vector getNextRow(ResultSet rs, ResultSetMetaData rsmd) throws SQLException {
Vector currentRow = new Vector();
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
currentRow.addElement(rs.getString(i));
}
return currentRow;
}
}
以上代码均已托管至公文传输系统实现代码/冲刺
冲刺第二天
| 第二天 | 负责人 | 工作量 |
|---|---|---|
| 完成数据库与对象的ORM | 陈夏林 | 2 |
| 实现模板应用实例化 | 陈夏林 | 2 |
| 精简优化数据库结构 | 陈夏林 | 1 |
| 设置加密和文件处理功能 | 谷丰宇、罗杰逊 | 3 |
| 文件上传下载模块 | 谷丰宇、罗杰逊 | 1 |
| 适配增加的功能 | 谷丰宇、罗杰逊 | 1 |
| 前端网页 | 董准、熊悠越 | 1 |
| 设计重定向url方向 | 董准、熊悠越 | 2 |
| 完成用户数据的相关内容 | 董准、熊悠越 | 1 |
| 明日任务安排 | 熊悠越 | 1 |
明日任务安排
| 第三天 | 工作量 |
|---|---|
| 调试数据库 | 2 |
| 完善接口 | 3 |
| 数据库初始化设置 | 4 |
| 完善文件上传下载模块 | 2 |
| 基于角色的权限控制设计 | 2 |
| 适配增加的功能 | 1 |
| 根据后端接口完善前端界面 | 3 |
| 继续完善用户数据的相关内容 | 2 |
| 明日任务安排 | 1 |