springBoot批量删除数据

基于springBoot批量删除数据
1.定义数据层接口

package com.cy.pj.sys.dao;

import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import com.cy.pj.sys.pojo.SysLog;
@Mapper
public interface SysLogDao {
/**
     * 添加基于id执行日志删除的方法
     */
    int deleteObjects(@Param("ids")Integer...ids);
    
}

2.编写mapper映射文件





        delete from sys_Logs
        
        
        
            
            id=#{id}
        
        
        
        
        where 1=2
        
        
    

3.写service接口层

package com.cy.pj.sys.service;

import com.cy.pj.sys.pojo.PageObject;
import com.cy.pj.sys.pojo.SysLog;

public interface SysLogService {
int deleteObjects(Integer...ids);
}

4.写service接口实现类

package com.cy.pj.sys.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cy.pj.sys.dao.SysLogDao;
import com.cy.pj.sys.pojo.PageObject;
import com.cy.pj.sys.pojo.SysLog;
import com.cy.pj.sys.service.SysLogService;

@Service
public class SysLogServiceImpl implements SysLogService {
    @Autowired
    private SysLogDao sysLogDao;
    @Override
    public int deleteObjects(Integer... ids) {
        //判定参数的合法性
        if (ids==null || ids.length==0)
            throw new IllegalArgumentException("请选择一个");
        
        //执行删除操作
        int rows;
        try {
        rows = sysLogDao.deleteObjects(ids);
        }catch(Throwable e) {
            e.printStackTrace();
            //发出报警信息(例如给运维人员发短信)

            throw new ServiceException("系统故障,正在恢复");
        }
        //对结果进行验证
        if (rows==0)
            throw new ServiceException("记录可能已经不存在");
        return rows;
    }

}

5.写concoller层

package com.cy.pj.sys.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cy.pj.sys.pojo.JsonResult;
import com.cy.pj.sys.service.SysLogService;

@Controller
public class SysLogController {
    @Autowired
    SysLogService sysLogService;
@RequestMapping("doDeleteObjects")
@ResponseBody
public JsonResult doDeleteObjects(Integer...ids) {
    sysLogService.deleteObjects(ids);
    return new JsonResult("删除  OK");    
}
}

6.现在开始前端的代码和js代码 其功能有通过input选中全部或取消全部


全选 用户名 操作 请求方法 请求参数 IP 执行时长
数据正在加载中...

你可能感兴趣的:(javascript,java)