当前位置:网站首页>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~~
边栏推荐
- 第三章、数据类型和变量
- Budget report ppt
- 3D semantic segmentation - scribed supervised lidar semantic segmentation
- MySQL linked table query, common functions, aggregate functions
- Sogou batch push software - Sogou batch push tool [2022 latest]
- 【数学建模绘图系列教程】二、折线图的绘制与优化
- 【读书会第13期】+FFmpeg开源项目
- Go language series: where does go come from and where will go?
- 柏睿数据加入阿里云PolarDB开源数据库社区
- easyui下拉框,增加以及商品的上架,下架
猜你喜欢

微信公众号开发之消息的自动回复

Replicate swin on Huawei ascend910_ transformer

【知识图谱】实践篇——基于医疗知识图谱的问答系统实践(Part4):结合问题分类的问题解析与检索语句生成

Don't believe these "rumors" in the process of preparing for the exam!

7.依赖注入

WPF implements user avatar selector

Rebudget: balance efficiency and fairness in market-based multi-core resource allocation by reallocating the budget at run time

Why 4everland is the best cloud computing platform for Web 3.0

中国芯片自给率大幅提升,导致外国芯片库存高企而损失惨重,美国芯片可谓捧起石头砸自己的脚...

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
随机推荐
152. 乘积最大子数组
企业直播风起:目睹聚焦产品,微赞拥抱生态
备考过程中,这些“谣言”千万不要信!
Homepage portal classification query
Who moved my memory and revealed the secret of 90% reduction in oom crash
激荡20年,芯片产能从零起步到反超美国,中国制造的又一大成就
2D 语义分割——DeepLabV3plus 复现
Is the online account opening of Founder futures reliable and safe?
从数字化到智能运维:有哪些价值,又有哪些挑战?
C#入门基础教程
用秩讨论线性方程组的解/三个平面的位置关系
如何使用 4EVERLAND CLI 在 IPFS 上部署应用程序
免费的低代码开发平台有哪些?
Unity is better to use the hot scheme Wolong
Test framework unittest test test suite, results output to file
Fudan University emba2022 graduation season - graduation does not forget the original intention and glory to embark on the journey again
复旦大学EMBA同学同行专题:始终将消费者的价值放在最重要的位置
Rosen's QT journey 99 QML table control tableview
WPF 实现用户头像选择器
【知识图谱】实践篇——基于医疗知识图谱的问答系统实践(Part5-完结):信息检索与结果组装