您的位置:首页 > 编程语言 > Java开发

关于mybatis的批量更新完整版

2016-11-01 10:05 190 查看

批量更新实现

Mapper.xml文件中

<!-- 批量拉黑 -->
  <update
id="batchUpdateState" 
parameterType="java.util.List">
         update plat2_token
                  <set>
                    cid_state="02"
                  </set>
         where cid in
                  <foreach
collection="list"
item="item"
index="index"
open="("
close=")"
separator=",">
                  #{item}
                 </foreach>
   </update>

 

Mapper文件中

/**
     * 批量拉黑
     * @param list
     * @return
     */
intbatchUpdateState(Listlist);

 

serviceImpl文件中

 

         /*

          * 批量拉黑用戶
          * @param
          * @return
          */
         @Override
         publicinttxbatchUpdateState(List<String>
ids)throwsException {
                 
                  intcount =
tokenMapper.batchUpdateState(ids);
                  returncount;
}

 

Action文件中

/**
          * 批量拉黑
          */
         publicvoidbatchUpdateState() {
                  try {
                          String[]
idListStrings =
po.getIdsList().split(",");
                          Listids =
null;
                         
                          if (idListStrings.length>0)
{
                                  
List<String>
idsList1=Ar
4000
rays.asList(idListStrings);
                                  
ids= newArrayList(idsList1);
                          }
                          System.out.println("=============="
+ ids);
                          tokenService.txbatchUpdateState(ids);
                          this.getMap().put(Constants.RET_CODE,
"0000");
                          this.getMap().put(Constants.RET_MSG,
"批量拉黑成功");
                          this.returnMap2Json(map);
                  } catch (Exceptione)
{
                          e.printStackTrace();
                          this.getMap().put(Constants.RET_CODE,
"9999");
                          this.getMap().put(Constants.RET_MSG,
"批量拉黑失败");
                          this.returnMap2Json(map);
                  }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java mybatis