当前位置:网站首页>Add batch delete
Add batch delete
2022-07-25 17:00:00 【Sooner or later, I will go bald】
Add delete and batch delete
Preface
The components of this time have been basically mentioned above , So don't tell them one by one , Directly improve the deficiencies of previous projects
Add and delete functions
One 、 newly added
1、 Add new button (userManage.jsp)
<a id="btn-add" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'"> newly added </a>
2、 Add a click event to the new button
$("#btn-add").click(function() {
// Clear the data of the previous form
$('#ff').form('clear');
$("#dd").dialog("open");
addFlag=1;
})
3、var A variable determines whether to add or modify
Because the form with modification is a , Therefore, it is necessary to distinguish whether to add or modify , The variable defaults to 0, Click Modify and it will be 1, Click add, then 0.
var addFlag=0;
4、 Event of form submission
function submitForm() {
/* * Click OK to submit the form to the background , And it's new / Modify a common method */
var href=null;
if(addFlag==2){
// modify
href=$("#ctx").val()+'/book.action?methodName=edit'
}else if(addFlag==1){
// increase
href=$("#ctx").val()+'/book.action?methodName=add'
}
$('#ff').form('submit', {
url:href,
success: function(data){
if(data==1){
$("#dd").dialog("close");
$('#dg').datagrid('reload');
}
}
});
}
5、 Write dao Methods and web
①、BookDao
// increase
public void add(Book book) throws Exception {
book.setBid((int)new Date().getTime());
super.executeUpdate("insert into t_mvc_book values(?,?,?)", book, new String[] {
"bid","bname","price"});
}
②、BookAction
public String add(HttpServletRequest req, HttpServletResponse resp) {
try {
bookDao.add(book);
ResponseUtil.writeJson(resp, 1);
} catch (Exception e) {
e.printStackTrace();
try {
ResponseUtil.writeJson(resp, 0);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
return null;
}
6. The page display 
Two . Delete
1、 Single delete
①、 stay datagrid Add a column and delete
columns:[[ {
field:'ck',checkbox:true}, {
field:'bid',title:'id',width:100}, {
field:'bname',title:' name ',width:100}, {
field:'price',title:' Price ',width:100}, {
field:' operation ',title:' operation ',width:100,align:'right',formatter: function(value,row,index){
return '<a href="javascript:void(0);" onclick="edit();"> modify </a>
< a href="javascript:void(0);" onclick="del();"> Delete </a>' }} ]]
②、 Methods of adding and deleting
Messager Components cannot send requests directly to the background , have access to ajax Send a request
function del() {
var row=$('#dg').datagrid("getSelected");
if(row){
var id=row.bid;
// messager Cannot send request to background
$.messager.confirm(' confirm ',' Are you sure you want to delete the record ?',function(r){
if (r){
$.ajax({
url:$("#ctx").val()+'/book.action?methodName=del&bid='+id,
success:function(data){
if(data==1){
$('#dg').datagrid('reload');
}
}
});
}
});
}else{
alert(" Please select the data to delete ");
}
}
③、dao Method
BookDao
// Delete
public void del(Book book) throws Exception {
super.executeUpdate(“delete from t_mvc_book where bid=?”, book, new String[] {“bid”});
}
④、BookAction
public String del(HttpServletRequest req, HttpServletResponse resp) {
try {
bookDao.del(book);
ResponseUtil.writeJson(resp, 1);
} catch (Exception e) {
e.printStackTrace();
try {
ResponseUtil.writeJson(resp, 0);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
return null;
}
Click delete ( Must be selected )
2、 Batch deletion
①、 Add batch delete button (userManage.jsp)
<a id="btn-batchDel" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'"> The batch operation </a>
②、 Add check box
$('#dg').datagrid({
url:$("#ctx").val()+'/book.action?methodName=datagrid',
pagination:true,
fitColumns:true,
// Add checkboxes
checkbox:true,
toolbar: '#tb',
columns:[[
// Set the column of the check box
{
field:'ck',checkbox:true},
{
field:'bid',title:'id',width:100},
{
field:'bname',title:' name ',width:100},
{
field:'price',title:' Price ',width:100},
{
field:' operation ',title:' operation ',width:100,align:'right',formatter: function(value,row,index){
return '<a href="javascript:void(0);" onclick="edit();"> modify </a> <a href="javascript:void(0);" onclick="del();"> Delete </a>'
}}
]]
});
③、 Add a batch delete click event
$("#btn-batchDel").click(function() {
var rows=$('#dg').datagrid("getSelections");
var ids=new Array();
if(rows !=null&& rows.length >0){
for (var i in rows) {
ids.push(rows[i].bid)
}
}
if(ids.length>0){
$.messager.confirm(' confirm ',' Are you sure you want to delete the record ?',function(r){
if (r){
$.ajax({
url:$("#ctx").val()+'/book.action?methodName=del&bids='+ids.join(","),
success:function(data){
if(data==1){
$('#dg').datagrid('reload');
}
}
});
}
});
}
});
~~```
④、 modify BookAction Code
```csharp
public String del(HttpServletRequest req, HttpServletResponse resp) {
try {
String ids = req.getParameter("bids");
String[] split = ids.split(",");
for (String s : split) {
book.setBid(Integer.parseInt(s));
bookDao.del(book);
}
ResponseUtil.writeJson(resp, 1);
} catch (Exception e) {
e.printStackTrace();
try {
ResponseUtil.writeJson(resp, 0);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
return null;
}
⑦、 effect
Click on the confirmation 

OK~~
边栏推荐
- 用秩讨论线性方程组的解/三个平面的位置关系
- Frustrated Internet people desperately knock on the door of Web3
- 微信公众号开发之消息的自动回复
- 【目标检测】YOLOv5跑通VOC2007数据集(修复版)
- 方正期货网上开户靠谱吗,开户安全吗?
- 基于redis6.2.4的redis cluster部署
- 动态规划题目记录
- 自定义mvc项目登录注册和树形菜单
- From digitalization to intelligent operation and maintenance: what are the values and challenges?
- 2D semantic segmentation -- deeplabv3plus reproduction
猜你喜欢

备考过程中,这些“谣言”千万不要信!

自定义mvc项目登录注册和树形菜单
![[mathematical modeling and drawing series tutorial] II. Drawing and optimization of line chart](/img/73/2b6fe0cf69fa013894abce331e1386.png)
[mathematical modeling and drawing series tutorial] II. Drawing and optimization of line chart

WPF implements user avatar selector

激荡20年,芯片产能从零起步到反超美国,中国制造的又一大成就

如何使用 4EVERLAND CLI 在 IPFS 上部署应用程序

博云容器云、DevOps平台斩获可信云“技术最佳实践奖”

在华为昇腾Ascend910上复现swin_transformer

HCIP笔记十一天

动态规划题目记录
随机推荐
[Nanjing University of Aeronautics and Astronautics] information sharing for the first and second examinations of postgraduate entrance examination
自定义mvc项目登录注册和树形菜单
ILSSI认证|六西格玛DMAIC的历程
HCIP笔记十一天
Rebudget: balance efficiency and fairness in market-based multi-core resource allocation by reallocating the budget at run time
3D 语义分割——Scribble-Supervised LiDAR Semantic Segmentation
MySQL视图
GTX1080Ti 光纤HDMI干扰出现闪屏1080Ti 闪屏解决方法
QT ListView 列表显示组件笔记
152. Product maximum subarray
Chapter 4: operators
Roson的Qt之旅#100 QML四种标准对话框(颜色、字体、文件、提升)
China's chip self-sufficiency rate has increased significantly, resulting in high foreign chip inventories and heavy losses. American chips can be said to have thrown themselves in the foot
免费的低代码开发平台有哪些?
How to deploy applications on IPFs using 4everland cli
3D语义分割——PVD
【目标检测】YOLOv5跑通VisDrone数据集
[redis] redis installation
Baidu rich text editor ueeditor image width 100% adaptive, mobile terminal
Chapter V: process control