1.url申请地址阐明
url:http://localhost:8091/item/delete
2.申请参数
申请参数:ids: 1474391964,1474391962,1474391963
3.返回值类型
{ text:'删除', iconCls:'icon-cancel', handler:function(){ var ids = getSelectionsIds(); if(ids.length == 0){ $.messager.alert('提醒','未选中商品!'); return ; } $.messager.confirm('确认','确定删除ID为 '+ids+' 的商品吗?',function(r){ if (r){ var params = {"ids":ids}; $.post("/item/delete",params, function(data){ if(data.status == 200){ $.messager.alert('提醒','删除商品胜利!',undefined,function(){ $("#itemList").datagrid("reload"); }); }else{ $.messager.alert("提醒",data.msg); } }); } }); }}
其中:var params = {"ids":ids};
$.post("/item/delete",params, function(data){...}
url:/item/delete,controller类要实现@RequestMapping("/item/delete") delete办法,params为ids
4.代码实现
4.1 编辑ItemController
/** * 业务: 商品删除 * url地址: http://localhost:8091/item/delete * 参数: ids: 1474391993,1474391997,1474391996 * 返回值: 零碎返回值VO:SysResult * List 能够赋值 name="list[0]" value=100 * name="list[1]" value=200 */ @RequestMapping("/delete") public SysResult deleteItems(Long[] ids){ itemService.deleteItems(ids); return SysResult.success(); }
4.2 编辑ItemService
@Override public void deleteItems(Long[] ids) { //1.将数组转化为汇合 List<Long> longList = Arrays.asList(ids); itemMapper.deleteBatchIds(longList); }
其中:
itemMapper.deleteBatchIds(longList) 为依据id批量删除item,为mybatis-plus框架技术。
如下为:mybatis-plus API技术文档
// 依据 entity 条件,删除记录int delete(@Param(Constants.WRAPPER) Wrapper<T> wrapper);// 删除(依据ID 批量删除)int deleteBatchIds(@Param(Constants.COLLECTION) Collection<? extends Serializable> idList);// 依据 ID 删除int deleteById(Serializable id);// 依据 columnMap 条件,删除记录int deleteByMap(@Param(Constants.COLUMN_MAP) Map<String, Object> columnMap);
参数阐明:
类型 | 参数名 | |
---|---|---|
Wrapper | Wrapper | 实体对象封装操作类(能够为null) |
Collection<? extends Serializable> | idsList | 主键ID列表汇合(不能为null以及empty) |
Serializable | id | 主键ID |
Mapping<String,Object> | columnMap | 表字段map对象 |