|
|
|
|
@ -10,48 +10,58 @@ import java.sql.ResultSet;
|
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
|
// 实现CommonDao接口,提供AuthInfo数据访问对象
|
|
|
|
|
public class AuthInfoDao implements CommonDao {
|
|
|
|
|
|
|
|
|
|
// 插入AuthInfo数据到数据库
|
|
|
|
|
@Override
|
|
|
|
|
public void insertData(Object o) throws SQLException {
|
|
|
|
|
AuthInfo authInfo = (AuthInfo) o;
|
|
|
|
|
AuthInfo authInfo = (AuthInfo) o; // 将Object对象转换为AuthInfo对象
|
|
|
|
|
|
|
|
|
|
Connection conn = DBUtil.getConnection();
|
|
|
|
|
Connection conn = DBUtil.getConnection(); // 获取数据库连接
|
|
|
|
|
|
|
|
|
|
// SQL插入语句
|
|
|
|
|
String sql = "insert into authInfo (authItem, isRead, isWrite, isChange, isDelete) values (?,?,?,?,?)";
|
|
|
|
|
PreparedStatement pstmt = conn.prepareStatement(sql);
|
|
|
|
|
// 设置SQL语句中的参数
|
|
|
|
|
pstmt.setString(1, authInfo.getAuthItem());
|
|
|
|
|
pstmt.setString(2, authInfo.getIsRead());
|
|
|
|
|
pstmt.setString(3, authInfo.getIsWrite());
|
|
|
|
|
pstmt.setString(4, authInfo.getIsChange());
|
|
|
|
|
pstmt.setString(5, authInfo.getIsDelete());
|
|
|
|
|
|
|
|
|
|
pstmt.executeUpdate();
|
|
|
|
|
pstmt.close();
|
|
|
|
|
pstmt.executeUpdate(); // 执行插入操作
|
|
|
|
|
pstmt.close(); // 关闭PreparedStatement
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 删除AuthInfo数据
|
|
|
|
|
@Override
|
|
|
|
|
public void deleteData(Object o) throws SQLException {
|
|
|
|
|
AuthInfo authInfo = (AuthInfo) o;
|
|
|
|
|
AuthInfo authInfo = (AuthInfo) o; // 将Object对象转换为AuthInfo对象
|
|
|
|
|
|
|
|
|
|
Connection conn = DBUtil.getConnection();
|
|
|
|
|
Connection conn = DBUtil.getConnection(); // 获取数据库连接
|
|
|
|
|
|
|
|
|
|
// SQL删除语句
|
|
|
|
|
String sql = "DELETE FROM authInfo WHERE authId = ?";
|
|
|
|
|
PreparedStatement pstmt = conn.prepareStatement(sql);
|
|
|
|
|
// 设置SQL语句中的参数
|
|
|
|
|
pstmt.setInt(1, authInfo.getAuthId());
|
|
|
|
|
|
|
|
|
|
pstmt.executeUpdate();
|
|
|
|
|
pstmt.close();
|
|
|
|
|
pstmt.executeUpdate(); // 执行删除操作
|
|
|
|
|
pstmt.close(); // 关闭PreparedStatement
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新AuthInfo数据
|
|
|
|
|
@Override
|
|
|
|
|
public void updateData(Object o) throws SQLException {
|
|
|
|
|
AuthInfo authInfo = (AuthInfo) o;
|
|
|
|
|
AuthInfo authInfo = (AuthInfo) o; // 将Object对象转换为AuthInfo对象
|
|
|
|
|
|
|
|
|
|
Connection conn = DBUtil.getConnection();
|
|
|
|
|
Connection conn = DBUtil.getConnection(); // 获取数据库连接
|
|
|
|
|
|
|
|
|
|
// SQL更新语句
|
|
|
|
|
String sql = "UPDATE authInfo SET authItem = ? ,isRead = ?,isWrite = ?,isChange = ?,isDelete = ? WHERE authId = ?";
|
|
|
|
|
PreparedStatement pstmt = conn.prepareStatement(sql);
|
|
|
|
|
// 设置SQL语句中的参数
|
|
|
|
|
pstmt.setString(1, authInfo.getAuthItem());
|
|
|
|
|
pstmt.setString(2, authInfo.getIsRead());
|
|
|
|
|
pstmt.setString(3, authInfo.getIsWrite());
|
|
|
|
|
@ -59,53 +69,59 @@ public class AuthInfoDao implements CommonDao {
|
|
|
|
|
pstmt.setString(5, authInfo.getIsDelete());
|
|
|
|
|
pstmt.setInt(6, authInfo.getAuthId());
|
|
|
|
|
|
|
|
|
|
pstmt.executeUpdate();
|
|
|
|
|
pstmt.close();
|
|
|
|
|
pstmt.executeUpdate(); // 执行更新操作
|
|
|
|
|
pstmt.close(); // 关闭PreparedStatement
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查询AuthInfo数据总数
|
|
|
|
|
@Override
|
|
|
|
|
public int queryDataNum() throws SQLException {
|
|
|
|
|
Connection conn = DBUtil.getConnection(); // 获取数据库连接
|
|
|
|
|
|
|
|
|
|
Connection conn = DBUtil.getConnection();
|
|
|
|
|
|
|
|
|
|
// SQL查询总数语句
|
|
|
|
|
String sql = "select count(*) from authInfo;";
|
|
|
|
|
PreparedStatement pstmt = conn.prepareStatement(sql);
|
|
|
|
|
ResultSet rs = pstmt.executeQuery();
|
|
|
|
|
ResultSet rs = pstmt.executeQuery(); // 执行查询操作
|
|
|
|
|
|
|
|
|
|
int num;
|
|
|
|
|
if (rs.next()) num = rs.getInt("count(*)");
|
|
|
|
|
else num = 0;
|
|
|
|
|
if (rs.next()) {
|
|
|
|
|
num = rs.getInt("count(*)"); // 获取总数
|
|
|
|
|
} else {
|
|
|
|
|
num = 0; // 如果没有数据,总数为0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rs.close();
|
|
|
|
|
pstmt.close();
|
|
|
|
|
rs.close(); // 关闭ResultSet
|
|
|
|
|
pstmt.close(); // 关闭PreparedStatement
|
|
|
|
|
|
|
|
|
|
return num;
|
|
|
|
|
return num; // 返回数据总数
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 分页查询AuthInfo数据
|
|
|
|
|
@Override
|
|
|
|
|
public ArrayList<AuthInfo> query(int start, int length) throws SQLException {
|
|
|
|
|
Connection conn = DBUtil.getConnection(); // 获取数据库连接
|
|
|
|
|
|
|
|
|
|
Connection conn = DBUtil.getConnection();
|
|
|
|
|
|
|
|
|
|
// SQL分页查询语句
|
|
|
|
|
String sql = "select * from authInfo limit ?, ?;";
|
|
|
|
|
PreparedStatement pstmt = conn.prepareStatement(sql);
|
|
|
|
|
// 设置分页参数
|
|
|
|
|
pstmt.setInt(1, start - 1);
|
|
|
|
|
pstmt.setInt(2, length);
|
|
|
|
|
ResultSet rs = pstmt.executeQuery();
|
|
|
|
|
ResultSet rs = pstmt.executeQuery(); // 执行查询操作
|
|
|
|
|
|
|
|
|
|
ArrayList<AuthInfo> list = new ArrayList<>();
|
|
|
|
|
ArrayList<AuthInfo> list = new ArrayList<>(); // 创建AuthInfo列表
|
|
|
|
|
AuthInfo authInfo;
|
|
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
authInfo = new AuthInfo(rs.getInt(1), rs.getString(2), rs.getString(3)
|
|
|
|
|
, rs.getString(4), rs.getString(5), rs.getString(6));
|
|
|
|
|
while (rs.next()) { // 遍历结果集
|
|
|
|
|
// 创建AuthInfo对象并添加到列表
|
|
|
|
|
authInfo = new AuthInfo(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6));
|
|
|
|
|
list.add(authInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rs.close();
|
|
|
|
|
pstmt.close();
|
|
|
|
|
rs.close(); // 关闭ResultSet
|
|
|
|
|
pstmt.close(); // 关闭PreparedStatement
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
return list; // 返回AuthInfo列表
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|