天天看點

如何在mybatis SQL查詢中使用IN

<!-- 刪除應用市場資訊 -->

 <delete id="delApplyMarker">

  delete from bi_applymarker where apply_id in <foreach item="item" index="index" collection="ids"

           open="(" separator="," close=")">

          #{item}

        </foreach>

 </delete>

 public void delApplyMarker(@Param(value="ids")List<Integer> applyMarkerId);

 @RequestMapping(value="/delApplyMarker",method=RequestMethod.GET)

 @ResponseBody

 public String delApplyMarker(HttpServletRequest request){

  ResultToJackson result = new ResultToJackson();

  Map<String, Object> applyMarker_map = new HashMap<String, Object>();//傳回給前臺的數據

  try {

   String applyMarkerId = request.getParameter("applyMarkerId");

   BIapplyMarkerMapper bIapplyMarkerMapper = (BIapplyMarkerMapper) factory.getBusinessProduct("applyMarker");

   String[] applyMarkerIds = applyMarkerId.split(",");

   List<Integer> ids = new ArrayList<Integer>();

   for(int i=0;i<applyMarkerIds.length;i++){

    ids.add(Integer.parseInt(applyMarkerIds[i]));

   }

   bIapplyMarkerMapper.delApplyMarker(ids);

   applyMarker_map.put("status", "true");

  } catch (Exception e) {

   e.printStackTrace();

   applyMarker_map.put("status", "false");

  }

  return result.getResultFromMap(applyMarker_map);

 }

}

繼續閱讀