1、实体类
public class Provider {
private Integer pid;
//供应商编码
private String providerCode;
//供应商名称
private String providerName;
//联系人
private String people;
//联系电话
private String phone;
//联系地址
private String address;
//传真
private String fax;
//描述
private String describe;
// 创建时间
private Date createDate;
public Provider() {
}
//get set 略
}
2、mapper接口
@Mapper//指定这是操作数据的mapper
public interface ProviderMapper {
int deleteProviderById(Integer pid);
}
3、mapper.xml
<mapper namespace="cn.qqqking.springboot.mapper.ProviderMapper">
<delete id="deleteProviderById">
delete from provider where pid = #{pid}
</delete>
4、controlle层
//删除供应商
@DeleteMapping("/provider/{pid}")
public String delete(@PathVariable("pid") Integer pid){
logger.info("delete :" + pid);
providerMapper.deleteProviderById(pid);
return "redirect:/providers";
}
5、前端
删除按钮
点击时添加属性del_uri 为/provider/加上对应id
<a href="#" th:attr="del_uri=@{/provider/}+${p.pid}" class="delete" ><img th:href="@{/img/schu.png}" src="../img/schu.png" alt="删除" title="删除"/></a>
点击按钮后 js 事件
$(function () {
$('.delete').click(function () {
//灰背景遮挡效果
$('.zhezhao').css('display', 'block');
$('#removeProv').fadeIn();
//获取点击删除的那个按键的del_uri,然后赋值给提交删除表单的那个action
$("#deleteForm").attr("action", $(this).attr("del_uri"));
});
//点击 确定
$('#yes').click(function () {
$("#deleteForm").submit();
$('.zhezhao').css('display', 'none');
$('#removeProv').fadeOut();
});
//点击 取消
$('#no').click(function () {
$('.zhezhao').css('display', 'none');
$('#removeProv').fadeOut();
});
});
点击后弹出是否确认删除,并且其他区域无效
此界面代码
<!--点击删除按钮后弹出的页面-->
<div class="zhezhao"></div>
<form method="post" id="deleteForm">
<input type="hidden" name="_method" value="delete">
<div class="remove" id="removeProv">
<div class="removerChid">
<h2>提示</h2>
<div class="removeMain" >
<p>你确定要删除吗?</p>
<a href="#" id="yes">确定</a>
<a href="#" id="no">取消</a>
</div>
</div>
</div>
通过点击 使用 js 添加属性到表单中
点击确定提交表单 进入controller进行删除