基本功能完成

This commit is contained in:
landaiqing 2023-06-10 01:13:29 +08:00
parent cb090dc1a2
commit 54d94a08fe
6 changed files with 170 additions and 8 deletions

View File

@ -102,4 +102,29 @@ public class UserDao {
JdbcUtils.closeConnection(null, preparedStatement, connection);
}
}
/**
* 通过ID 删除
* */
public int deleteUser(Integer id){
Connection connection = null;
PreparedStatement preparedStatement = null;
try {
connection = JdbcUtils.getConnection();
JdbcUtils.beginTransaction(connection);
preparedStatement = connection.prepareStatement("DELETE from `user` WHERE `userId` = ?;");
preparedStatement.setInt(1,id);
Integer result = preparedStatement.executeUpdate();
JdbcUtils.commitTransaction(connection);
return result;
} catch (SQLException e) {
JdbcUtils.rollBackTransaction(connection);
throw new RuntimeException(e);
} finally {
JdbcUtils.closeConnection(null, preparedStatement, connection);
}
}
}

View File

@ -26,4 +26,12 @@ public class UserService {
public int reply(UserEntity userEntity){
return userDao.reply(userEntity);
}
/**
* 通过ID 删除
* */
public int deleteUser(Integer id){
return userDao.deleteUser(id);
}
}

View File

@ -0,0 +1,44 @@
package com.landaiqing.servlet.system;
import com.landaiqing.service.UserService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/deleteUser")
public class DeleteUser extends HttpServlet {
private UserService userService=new UserService();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String idStr = req.getParameter("id");
if (idStr==null || idStr==""){
req.setAttribute("errorMsg","ID的值不能为空!!!");
req.getRequestDispatcher("./error.jsp").forward(req,resp);
return;
}
try {
Integer id = Integer.parseInt(idStr);
int result = userService.deleteUser(id);
if (result > 0) {
// req.getRequestDispatcher("showFlight.jsp").forward(req,resp);
resp.sendRedirect("./System/index.jsp");
}else {
req.setAttribute("errorMsg","删除失败!!!");
req.getRequestDispatcher("./error.jsp").forward(req,resp);
}
} catch (NumberFormatException e) {
req.setAttribute("errorMsg","类型转换异常,id 不能转换成Int类型!!!");
req.getRequestDispatcher("./error.jsp").forward(req,resp);
e.printStackTrace();
}catch (Exception e){
req.setAttribute("errorMsg","系统异常!!!");
req.getRequestDispatcher("./error.jsp").forward(req,resp);
}
}
}

View File

@ -122,7 +122,7 @@
<div class="layui-form-item" pane>
<label class="layui-form-label">是否有效</label>
<div class="layui-input-block">
<input type="text" id="isValid" name="open" lay-filter="required" class="layui-input" >
<input type="text" id="isValid" placeholder="1 为有效/0为无效" name="open" lay-filter="required" class="layui-input" >
</div>
</div>
<div class="layui-form-item">
@ -177,7 +177,7 @@
<div class="layui-form-item" pane>
<label class="layui-form-label">是否有效</label>
<div class="layui-input-block">
<input type="text" id="isValid" name="open" lay-filter="required" class="layui-input" >
<input type="text" id="isValid" placeholder="1 为有效/0为无效" name="open" lay-filter="required" class="layui-input" >
</div>
</div>
<div class="layui-form-item">
@ -252,6 +252,7 @@
layer.msg('开启成功'), {
offset: '6px'
}
window.location.reload();
})
}
@ -269,7 +270,9 @@
layer.msg('关闭成功'), {
offset: '6px'
}
window.location.reload();
})
}
function upAdateAdmin(){

View File

@ -17,6 +17,23 @@
<script src="//unpkg.com/layui@2.8.0/dist/layui.js"></script>
</head>
<body>
<script type="text/html" id="toolbarDemo">
<div class="layui-btn-container">
<%-- <button class="layui-btn layui-btn-sm" lay-event="addAdmin">添加管理员</button>--%>
</div>
</script>
<script type="text/html" id="barDemo">
<div class="layui-clear-space">
<%-- <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>--%>
<a class="layui-btn layui-btn-xs" lay-event="more">
更多
<i class="layui-icon layui-icon-down"></i>
</a>
</div>
</script>
<table class="layui-hide" id="ID-table-demo-data"></table>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
@ -39,6 +56,7 @@
// 已知数据渲染
var inst = table.render({
elem: '#ID-table-demo-data'
,toolbar: '#toolbarDemo'
,cols: [[ //标题栏
{field: 'userId', title: 'ID', width: 80, sort: true}
,{field: 'nickName', title: '昵称', width: 130}
@ -48,9 +66,53 @@
{field:'dateTime', title: '评论时间', width:130, },
{field:'replyContent', title: '回复内容', width:200, },
{field:'replyDateTime', title: '回复时间', width:130, },
{fixed: 'right', title:'操作', width: 134, minWidth: 125, toolbar: '#barDemo'}
// {fixed: 'right', title:'操作', width: 134, minWidth: 125, toolbar: '#barDemo'}
]]
]],done:function (){
// 触发单元格工具事件
table.on('tool(ID-table-demo-data)', function(obj){ // 双击 toolDouble
var data = obj.data; // 获得当前行数据
// console.log(obj)
if(obj.event === 'more'){
// 更多 - 下拉菜单
dropdown.render({
elem: this, // 触发事件的 DOM 对象
show: true, // 外部事件触发即显示
data: [{
title: '查看',
id: 'detail'
},{
title: '删除',
id: 'del'
}],
click: function(menudata){
if(menudata.id === 'detail'){
layer.msg('ID:'+ data.userId
+'\n昵称:'+data.nickName
+"\nQ Q:"+data.qQ
+"\nEmail:"+data.email
+"\n评论内容:"+data.content
+"\n评论时间:"+data.dateTime
+"\n回复内容:"+data.replyContent
+"\n回复时间:"+data.replyDateTime
);
} else if(menudata.id === 'del'){
layer.confirm('真的删除行 [id: '+ data.userId +'] 么', function(){
obj.del(); // 删除对应行tr的DOM结构
// layer.close(index);
// deleteAdmin(data.adminId);
deleteUser(data.userId);
// 向服务端发送删除指令
});
}
},
align: 'right', // 右对齐弹出
style: 'box-shadow: 1px 1px 10px rgb(0 0 0 / 12%);' // 设置额外样式
})
}
});
}
,data: result.data
//,skin: 'line' // 表格风格
//,even: true
@ -66,6 +128,22 @@
})
}
getDate();
function deleteUser(id){
axios({
// 请求方式
method: 'get',
// 请求的地址
url: 'http://localhost:8080${pageContext.request.contextPath}/deleteUser',
// URL 中的查询参数
params: {
id:id,
}
}).then(function (result) {
layer.msg('删除成功!'), {
offset: '6px'
}
})
}
</script>

View File

@ -59,7 +59,7 @@
<div class="main">
<div class="header">
<div style="display: flex;flex-direction: row;flex-wrap: nowrap;align-items: center;">
<div style="display: flex;position: fixed;flex-direction: row;flex-wrap: nowrap;align-items: center;z-index: 99999;background-color: white">
<div style="width: 570px;height: 45px;">
<span style="font-size: 2rem;font-weight: 700;font-family: FZShuTi;color:coral;">留 &nbsp;&nbsp;言&nbsp;&nbsp; 本</span>
</div>
@ -90,7 +90,7 @@
</div>
</div>
<blockquote class="layui-elem-quote layui-text">
<blockquote style="margin-top: 6%" class="layui-elem-quote layui-text">
留言列表
</blockquote>
@ -226,7 +226,7 @@
<div class="show">
<div class="show-content">
<div class="show-name">
<div class="avtors"><img src="./static/img/touxiang.png" alt=""
<div class="avtors"><img src="./static/img/头像修改.png" alt=""
style="width: 40px;height: 40px;border-radius: 50%;"></div>
<span style="margin-left: 10px;font-size: 1rem;">${list.nickName}</span>
</div>
@ -350,8 +350,10 @@
}
}).then(function (result) {
//定位 span id 名称 error 修改
console.log(result);
// console.log(result);
window.location.reload();
})
}
// 回复
function reply(userId){
@ -368,8 +370,10 @@
}
}).then(function (result) {
//定位 span id 名称 error 修改
console.log(result);
// console.log(result);
window.location.reload();
})
}
$(function () {