关于mybatis的批量删除操作

来源:互联网 发布:莫知我哀全文 编辑:程序博客网 时间:2024/05/16 00:47

批量删除功能是实现

Mapper.xml文件写法

<!-- 批量删除用户 --> 

  <deleteid = "deleteUserWithBatch"parameterType ="java.util.List"> 

    <![CDATA[ 

       delete from plat_cust where cid in 

    ]]> 

    <foreachcollection="list"item = "model" open="("separator=","close=")">

    #{ model} 

    </foreach> 

</delete>

Mapper中的写法

/**

     * 批量删除用户

     * @param ids

     * @return

     */

intdeleteUserWithBatch(Listlist);

 

serviceImpl中的写法

/*

          * 批量删除用户

          * @param

          * @return

          */

         @Override

         publicinttxDeleteUserWithBatch(List<String>ids)throwsException {

                 

                  intcount =custMapper.deleteUserWithBatch(ids);

              returncount;

}

 

Action中的写法

//批量删除用户

   

    publicvoiddeleteBatch() {

    try {

              String[]idsList =po.getIdStringList().split(",");

              Listids =null;

             

              if (idsList.length>0) {

                       List<String>idsList1=Arrays.asList(idsList);

                                   ids= newArrayList(idsList1);

                          }

              System.out.println("==============" + ids);

                          custService.txDeleteUserWithBatch(ids);

                          this.getMap().put(Constants.RET_CODE,"0000");

                          this.getMap().put(Constants.RET_MSG,"成功");

                  } catch (Exceptione) {

                          e.printStackTrace();

                          this.getMap().put(Constants.RET_CODE,"9999");

                          this.getMap().put(Constants.RET_MSG,"查询异常");

                          this.returnMap2Json(map);

                  }

    }

0 0