数据列表删除效果(涉及Ajax和strut2框架)

1.jsp页面删除按钮的单击事件

Jsp:

$('#delbtn_wait').click(function(){
            var data=getValue();
            if(data==""){
                alert("请选择需要删除的选项");
                return;
            }
            $("#checkList").val(data);
            if(confirm("确定删除该立项信息吗?删除后不可回复")){
                $.ajax({
                    async:false,
                    type: "POST",
                    data:$("form").serialize(),
                    url: '/bistone/showdelProjectApprove.action?data='+data
                });
                alert("删除样本库成功!");
                refreshwindow();
            }           
        //关闭子窗口,删除后自动刷新页面
        function refreshwindow() {
            window.location.href = window.location.href.replace(/#/g, '');
        }               
        });

2.配置Action的的映射文件

Strul.xml:


            /jsp/ptl/listApproveDraft.action?sDto.approveUserId=${approveUserId}&sDto.approveDeptId=${approveDeptId}
        

3.Action文件相当于Servlet层

ProjectApproveaction.java:

public String showdelProjectApprove(){
        HttpServletRequest request = ServletActionContext.getRequest();
        SearchConditionDto sdto = (SearchConditionDto)MemcacheUtil.getMemcached("sdto",request);
        this.ids = checkList.split(",");//要删除样本的所有的id
        if (ids != null && ids.length > 0) {
            boolean flag = false;
            for (int i = 0; i < ids.length; i++) {
                projectApprove = new ProjectApproveDto();
                projectApprove.setApproveId(ids[i]);
                //执行删除
                String opName = projectApproveService.listProjectApproveDraft(uid).get(0).getProjectName();
                flag = this.projectApproveService.showdelProjectApprove(projectApprove);
/**当projectApproveService里面还没有创建showdelProjectApprove方法时,鼠标放上去会提示在Service文件中创建showdelProjectApprove方法(ctrl+1也行),点击该选项会自动跳转到Service界面,找到Service层的实行按类鼠标放在类名处,实现接口未实现的方法即可。不用手动敲。*/
            }
            if (flag) {
                return SUCCESS;
            } else {
                addActionError("删除失败!");
                return INPUT;
            }
        }
        addActionError("删除失败!");
        return INPUT;
    }

4.service的接口类

public boolean showdelProjectApprove(ProjectApproveDto dto);

4.1service接口的实现类

@Override
    public boolean showdelProjectApprove(ProjectApproveDto dto) {
        // 调用Dao里面的showdelProjectApprove方法
        return this.projectApproveDao.showdelProjectApprove(dto);
    }

5.Dao的接口类

public boolean showdelProjectApprove(ProjectApproveDto dto);

5.1Dao接口的实现类

@Override
    public boolean showdelProjectApprove(ProjectApproveDto dto) {
        // TODO Auto-generated method stub
        boolean flag = false;   
        try {
            flag = getSqlMapClientTemplate().delete("showdelProjectApprove", dto) > 0 ? true : false;
            
        } catch (DataAccessException e) {
            // TODO Auto-generated catch block
            logger.error("删除立项数据错误showdelProjectApprove:"+e.getMessage());
        }
        return flag;
    }

6.找到showdelProjectApprove的sql映射文件

sqlmap.xml


        delete from tb_d_project_approve where approve_id = #approveId#
    

你可能感兴趣的:(数据列表删除效果(涉及Ajax和strut2框架))