com.inks.hb的部分修改

增加了可读性
main
pyveob72j 11 months ago
parent 49b35b2252
commit 6b30d2adf5

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/touge" vcs="Git" /> <mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/touge/hotelbook-JavaWeb-master" vcs="Git" />
</component> </component>
</project> </project>

@ -1,38 +1,49 @@
package com.inks.hb.authinfo.controller; package com.inks.hb.authinfo.controller;
import com.inks.hb.authinfo.pojo.AuthInfo; import com.inks.hb.authinfo.pojo.AuthInfo; // 引入AuthInfo实体类
import com.inks.hb.authinfo.service.AuthService; import com.inks.hb.authinfo.service.AuthService; // 引入AuthService接口
import com.inks.hb.authinfo.service.AuthServiceImpl; import com.inks.hb.authinfo.service.AuthServiceImpl; // 引入AuthServiceImpl实现类
import com.inks.hb.common.ExportExcel; import com.inks.hb.common.ExportExcel; // 引入ExportExcel工具类
import javax.servlet.annotation.WebServlet; import javax.servlet.annotation.WebServlet; // 引入@WebServlet注解
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet; // 引入HttpServlet类
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest; // 引入HttpServletRequest接口
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse; // 引入HttpServletResponse接口
import java.sql.SQLException; import java.sql.SQLException; // 引入SQLException异常类
import java.util.ArrayList; import java.util.ArrayList; // 引入ArrayList类
// 使用@WebServlet注解定义Servlet的名称和URL映射
@WebServlet(name = "AuthInfoExcelServlet", value = "/AuthInfoExcelServlet") @WebServlet(name = "AuthInfoExcelServlet", value = "/AuthInfoExcelServlet")
public class AuthInfoExcelServlet extends HttpServlet { public class AuthInfoExcelServlet extends HttpServlet {
// 重写doPost方法调用doGet方法
protected void doPost(HttpServletRequest request, HttpServletResponse response) { protected void doPost(HttpServletRequest request, HttpServletResponse response) {
this.doGet(request, response); this.doGet(request, response);
} }
// 重写doGet方法处理HTTP GET请求
protected void doGet(HttpServletRequest request, HttpServletResponse response) { protected void doGet(HttpServletRequest request, HttpServletResponse response) {
// 创建AuthService实例
AuthService service = new AuthServiceImpl(); AuthService service = new AuthServiceImpl();
// 声明并初始化AuthInfo列表
ArrayList<AuthInfo> infoArrayList = null; ArrayList<AuthInfo> infoArrayList = null;
try { try {
// 查询所有AuthInfo并赋值给infoArrayList
infoArrayList = service.query(1, service.queryAuthInfoNum()); infoArrayList = service.query(1, service.queryAuthInfoNum());
} catch (SQLException e) { } catch (SQLException e) {
// 捕获并打印SQLException异常
e.printStackTrace(); e.printStackTrace();
} }
// 定义Excel表头
String[] headers = {"权限ID", "权限名称", "可读", "可写", "可改", "可删"}; String[] headers = {"权限ID", "权限名称", "可读", "可写", "可改", "可删"};
// 定义导出的Excel文件名
String fileName = "权限信息"; String fileName = "权限信息";
// 创建ExportExcel实例
ExportExcel<AuthInfo> ee = new ExportExcel<>(); ExportExcel<AuthInfo> ee = new ExportExcel<>();
// 调用exportExcel方法导出Excel文件
ee.exportExcel(headers, infoArrayList, fileName, response); ee.exportExcel(headers, infoArrayList, fileName, response);
} }
} }

@ -16,48 +16,52 @@ import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
* * Servlet
* '' * ''
* pojotoGson * PojotoGson
*/ */
@WebServlet(value = "/AuthInfoServlet", name = "AuthInfoServlet") @WebServlet(value = "/AuthInfoServlet", name = "AuthInfoServlet")
public class AuthInfoServlet extends HttpServlet { public class AuthInfoServlet extends HttpServlet {
// 重写doPost方法调用doGet方法以处理POST请求
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
this.doGet(request, response); this.doGet(request, response);
} }
// 重写doGet方法处理GET请求
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
// 设置请求和响应的字符编码
request.setCharacterEncoding("utf-8"); request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8"); response.setContentType("text/html;charset=utf-8");
// 获取响应输出流
PrintWriter out = response.getWriter(); PrintWriter out = response.getWriter();
// 从请求中获取分页参数和操作类型
int page = Integer.parseInt(request.getParameter("page")); // 当前页码 int page = Integer.parseInt(request.getParameter("page")); // 当前页码
int limit = Integer.parseInt(request.getParameter("limit")); // 每页的数据量 int limit = Integer.parseInt(request.getParameter("limit")); // 每页的数据量
int make = Integer.parseInt(request.getParameter("make")); int make = Integer.parseInt(request.getParameter("make")); // 操作类型
// 调用service // 创建AuthService实例
AuthService service = new AuthServiceImpl(); AuthService service = new AuthServiceImpl();
// 默认输出信息 // 初始化返回信息
String code = "0"; //状态码 String code = "0"; // 状态码默认为0表示成功
String msg = "数据查询正常"; //状态信息 String msg = "数据查询正常"; // 状态信息,默认为正常
String count = ""; //数据总数 String count = ""; // 数据总数,初始化为空字符串
ArrayList<AuthInfo> list = new ArrayList<>(); //数据内容 ArrayList<AuthInfo> list = new ArrayList<>(); // 数据内容列表
//单个全局属性 // 声明单个全局属性
int authId; //权限ID int authId; // 权限ID
String authItem = ""; //权限名称 String authItem = ""; // 权限名称
String isRead; //可读 String isRead; // 可读
String isWrite; //可写 String isWrite; // 可写
String isChange; //可改 String isChange; // 可改
String isDelete; //可删 String isDelete; // 可删
AuthInfo authInfo = null; AuthInfo authInfo = null; // AuthInfo对象
try { try {
// 根据操作类型执行不同的逻辑
// 状态标志 make 0重载 1新增 2修改 3搜索 4删除
if (make == 2) { if (make == 2) {
// 修改权限信息
authId = Integer.parseInt(request.getParameter("authId")); authId = Integer.parseInt(request.getParameter("authId"));
authItem = request.getParameter("authItem"); authItem = request.getParameter("authItem");
isRead = request.getParameter("isRead"); isRead = request.getParameter("isRead");
@ -65,38 +69,33 @@ public class AuthInfoServlet extends HttpServlet {
isChange = request.getParameter("isChange"); isChange = request.getParameter("isChange");
isDelete = request.getParameter("isDelete"); isDelete = request.getParameter("isDelete");
authInfo = new AuthInfo(authId, authItem, isRead, isWrite, isChange, isDelete); authInfo = new AuthInfo(authId, authItem, isRead, isWrite, isChange, isDelete);
service.updateAuthInfo(authInfo); // 更新权限信息
} else if (make == 3) { } else if (make == 3) {
// 搜索权限信息
authItem = request.getParameter("authItem"); authItem = request.getParameter("authItem");
authInfo = service.query(authItem); // 查询权限信息
list.clear(); // 清空列表
list.add(authInfo); // 添加查询结果到列表
} }
switch (make) { // 根据操作类型获取数据
case 2:
service.updateAuthInfo(authInfo);
break;
case 3:
authInfo = service.query(authItem);
list.clear();
list.add(authInfo);
break;
}
if (make != 3) { if (make != 3) {
list = service.query(page, limit); list = service.query(page, limit); // 分页查询权限信息
count = String.valueOf(service.queryAuthInfoNum()); count = String.valueOf(service.queryAuthInfoNum()); // 获取权限信息总数
} else { } else {
if (authInfo.getAuthId() == 0) { // 如果搜索结果为空则设置count为0否则为1
count = "0"; count = (authInfo.getAuthId() == 0) ? "0" : "1";
} else {
count = "1";
}
} }
} catch (SQLException e) { } catch (SQLException e) {
// 捕获到SQLException异常设置错误状态码和信息
code = "1"; code = "1";
msg = "数据查询出现异常"; msg = "数据查询出现异常";
e.printStackTrace(); e.printStackTrace(); // 打印异常堆栈信息
} finally { } finally {
// 创建PojotoGson对象并序列化为JSON字符串
PojotoGson pojotoGson = new PojotoGson(code, msg, count, list); PojotoGson pojotoGson = new PojotoGson(code, msg, count, list);
Gson gson = new Gson(); Gson gson = new Gson();
out.print(gson.toJson(pojotoGson)); out.print(gson.toJson(pojotoGson)); // 输出JSON字符串
} }
} }
} }

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

@ -6,46 +6,50 @@ import com.inks.hb.authinfo.pojo.AuthInfo;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
// 实现AuthService接口提供AuthInfo业务逻辑服务
public class AuthServiceImpl implements AuthService { public class AuthServiceImpl implements AuthService {
private AuthInfoDao dao = new AuthInfoDao(); private AuthInfoDao dao = new AuthInfoDao(); // AuthInfo数据访问对象
// 查询AuthInfo记录总数
@Override @Override
public int queryAuthInfoNum() throws SQLException { public int queryAuthInfoNum() throws SQLException {
return dao.queryDataNum(); // 调用DAO层的方法查询总数
return dao.queryDataNum();
} }
// 根据ID查询AuthInfo记录
@Override @Override
public AuthInfo query(int authId) throws SQLException { public AuthInfo query(int authId) throws SQLException {
AuthInfo authInfo = new AuthInfo(); AuthInfo authInfo = new AuthInfo(); // 创建AuthInfo对象
authInfo.setAuthId(authId); authInfo.setAuthId(authId); // 设置查询条件
return (AuthInfo) dao.query(authInfo); return (AuthInfo) dao.query(authInfo); // 调用DAO层的方法进行查询
} }
// 根据权限项名称查询AuthInfo记录
@Override @Override
public AuthInfo query(String authItem) throws SQLException { public AuthInfo query(String authItem) throws SQLException {
AuthInfo authInfo = new AuthInfo(); AuthInfo authInfo = new AuthInfo(); // 创建AuthInfo对象
authInfo.setAuthItem(authItem); authInfo.setAuthItem(authItem); // 设置查询条件
return dao.queryName(authInfo); return dao.queryName(authInfo); // 调用DAO层的方法进行查询
} }
// 分页查询AuthInfo记录
@Override @Override
public ArrayList query(int page, int limit) throws SQLException { public ArrayList query(int page, int limit) throws SQLException {
int start = (page * limit) - limit + 1; // 计算分页查询的起始位置
int start = (page * limit) - limit + 1; //每一页的起始位置 if (start < 1) {
start = 1; // 如果起始位置小于1则设置为1
if (start < 1) }
start = 1;
return dao.query(start, limit); return dao.query(start, limit); // 调用DAO层的方法进行分页查询
} }
// 更新AuthInfo记录
@Override @Override
public void updateAuthInfo(AuthInfo authInfo) throws SQLException { public void updateAuthInfo(AuthInfo authInfo) throws SQLException {
dao.updateData(authInfo); // 调用DAO层的方法进行更新操作
dao.updateData(authInfo);
} }
} }

@ -1,24 +1,31 @@
package com.inks.hb.billinfo.pojo; package com.inks.hb.billinfo.pojo;
/** /**
* *
*/ */
public class BillInfo { public class BillInfo {
// 账单ID
private int billId; private int billId;
// 审核ID
private String checkedId; private String checkedId;
// 费用金额
private String costMoney; private String costMoney;
// 费用日期
private String costDate; private String costDate;
// 备注
private String remark; private String remark;
// 默认构造方法
public BillInfo() { public BillInfo() {
super(); super();
} }
// 带参数的构造方法用于创建BillInfo对象时初始化字段
public BillInfo(int billId, String checkedId, String costMoney, String costDate, String remark) { public BillInfo(int billId, String checkedId, String costMoney, String costDate, String remark) {
this.billId = billId; this.billId = billId;
this.checkedId = checkedId; this.checkedId = checkedId;
@ -27,46 +34,57 @@ public class BillInfo {
this.remark = remark; this.remark = remark;
} }
// 获取账单ID
public int getBillId() { public int getBillId() {
return billId; return billId;
} }
// 设置账单ID
public void setBillId(int billId) { public void setBillId(int billId) {
this.billId = billId; this.billId = billId;
} }
// 获取审核ID
public String getCheckedId() { public String getCheckedId() {
return checkedId; return checkedId;
} }
// 设置审核ID
public void setCheckedId(String checkedId) { public void setCheckedId(String checkedId) {
this.checkedId = checkedId; this.checkedId = checkedId;
} }
// 获取费用金额
public String getCostMoney() { public String getCostMoney() {
return costMoney; return costMoney;
} }
// 设置费用金额
public void setCostMoney(String costMoney) { public void setCostMoney(String costMoney) {
this.costMoney = costMoney; this.costMoney = costMoney;
} }
// 获取费用日期
public String getCostDate() { public String getCostDate() {
return costDate; return costDate;
} }
// 设置费用日期
public void setCostDate(String costDate) { public void setCostDate(String costDate) {
this.costDate = costDate; this.costDate = costDate;
} }
// 获取备注
public String getRemark() { public String getRemark() {
return remark; return remark;
} }
// 设置备注
public void setRemark(String remark) { public void setRemark(String remark) {
this.remark = remark; this.remark = remark;
} }
// 重写toString方法用于打印BillInfo对象的字符串表示
@Override @Override
public String toString() { public String toString() {
return "BillInfo{" + return "BillInfo{" +

@ -5,18 +5,33 @@ import java.util.Base64;
public class MD5 { public class MD5 {
/**
* MD5Base64
* @param str
* @return Base64
*/
public String getMD5(String str) { public String getMD5(String str) {
// 在输入字符串前添加盐值
String Salt = "mH8yhBL-n*j-2gmC" + str; String Salt = "mH8yhBL-n*j-2gmC" + str;
// 将带盐值的字符串转换为字节数组并进行Base64编码
return Base64.getEncoder().encodeToString(Salt.getBytes(StandardCharsets.UTF_8)); return Base64.getEncoder().encodeToString(Salt.getBytes(StandardCharsets.UTF_8));
} }
/**
* MD5
* @param newStr
* @param oldStr
* @return truefalse
*/
public boolean checkMD5(String newStr, String oldStr) { public boolean checkMD5(String newStr, String oldStr) {
// 比较新字符串的MD5哈希值与旧字符串的哈希值是否相等
return getMD5(newStr).equals(oldStr); return getMD5(newStr).equals(oldStr);
} }
public static void main(String[] args) { public static void main(String[] args) {
// 创建MD5类的实例
MD5 md5 = new MD5(); MD5 md5 = new MD5();
// 输出字符串"toor"的MD5哈希值
System.out.println(md5.getMD5("toor")); System.out.println(md5.getMD5("toor"));
} }
} }

Loading…
Cancel
Save