Based on SSM bulk deletion

Simply delete the feature is easy to implement, but the bulk delete in the actual development is a very common feature, do the project just recently used this feature. So recorded.
In fact, bulk delete and delete is not much difference, just modify the sql statement, then the parameters passed in the form of an array, then loop the array in the sql statement, sql statement execution. Directly on the code.
DAO layer Code

    /**批量删除简历*/
    void deleteMany(String[] resumeID);

sevice Interface

    /**批量删除*/
    void deleteMany(String resumeID[]);

service implementation class codes layer

    /**批量删除*/
    public void deleteMany(String[] resumeID){
         resumeDao.deleteMany(resumeID);
    }

controller layer

     /**
     * 功能描述: 批量删除
     * @auther: yxc
     * @return: DataResult
     * @date: 2019/12/20
     */
    @ApiOperation(value = "批量删除简历")
    @ApiImplicitParam(value = "批量删除",name="resumeID",dataType = "String",paramType = "query",allowMultiple =true )
    @ResponseBody
    @RequestMapping(value = "deleteMany",method = RequestMethod.GET)
    public DataResult deleteMany(String[] resumeID){
        DataResult result=new DataResult();
        resumeService.deleteMany(resumeID);
        result.setStatus(0);
        result.setMsg("删除成功");
        return result;
    }

About API notes, it is based on the swagger of a use tools, reference Bowen swagger use of simple annotations

The final step is to configure the sql statement

    <delete id="deleteMany" parameterType="String">
        delete from hire_resume where resume_id in
        <foreach item="resumeID" collection="array" open="(" separator="," close=")">
            #{resumeID}
        </foreach>
    </delete>

Learned of the database you should be able to quickly understand this sql statement it! Loop through the array, the element of the array in one in the inside, this will delete all data in the back of the open and close indicate the beginning and end: as
delete from hire_resume where resume_id in (1001,1002,1003 )
In fact, the relative bulk delete and Yan was quite a simple application

Published 33 original articles · won praise 37 · views 4382

Guess you like

Origin blog.csdn.net/weixin_42142899/article/details/103652436