1.product-view.jsp
<div class="page-container" style="padding-top: 15px; padding-left: 25px; padding-right: 25px;">
<div class="cl pd-5 bg-1 bk-gray mt-20 radius">
<span class="l"><a href="javascript:;" οnclick="add()" class="btn btn-danger radius"><i class="Hui-iconfont"></i> 添加产品</a>
<a href="javascript:;" οnclick="removes()" class="btn btn-danger radius"><i class="Hui-iconfont"></i> 批量删除</a> </span>
</div>
<div class="mt-20">
<table class="table table-border table-bordered table-hover table-bg table-sort" id="userTable">
<thead>
<tr class="text-c">
<th width="25"><input type="checkbox" name="" value=""></th>
<th width="">产品名称</th>
<th width="">产品价格</th>
<th width="">产品库存</th>
<th width="">产品状态</th>
<th width="130">操作</th>
</tr>
</thead>
<tbody class="text-c">
</tbody>
</table>
</div>
</div>
2.脚本
/*删除*/
function remove(obj,id){
var tr = $(obj).parents("tr");
var input = tr.find("input");
layer.confirm('确认要删除吗?',function(index){
$.ajax({
'url' : '/web10-7/product/remove',
'type' : 'post',
'dataType' : 'json',
'data' : {"id" : input.val()},
'success' : function(data, statusText) {
if(data.status){
layer.msg("删除成功!");
table.ajax.reload();
}else{
layer.msg("删除失败!");
}
},
'error' : function(xhr, e1, e2) {
layer.msg("系统错误!");
}
});
});
}
3.ProductAction.java
/**
* 删除产品
*/
@ResponseBody
@RequestMapping("/remove")
public CallbackResult removeUser(HttpServletRequest request){
String id = request.getParameter("id");
Product product=new Product();
product.setId(id);
CallbackResult callbackResult = new CallbackResult();
callbackResult.setStatus(productService.remove(product));
return callbackResult;
}
4.ProductService.java
public Boolean remove(Product product) {
return productDao.remove(product) == 1;
}
5.ProductMapper.xml
<update id="remove" parameterType="fuck.pojo.Product" flushCache="true">
update product set status = 0 where id = #{id}
</update>