mybatis in查詢
阿新 • • 發佈:2019-02-17
mybatis部分
xml程式碼
<select id="findEDById" parameterType="EarDisease" resultType="java.util.Map"> SELECT t1.id AS earDiseaseId,t1.name,t1.content,t2.name AS systemName FROM dt_ear_disease AS t1 LEFT JOIN dt_ear_system AS t2 ON t2.num=t1.system_id WHERE t1.id IN <foreach item="item" index="index" collection="earDiseaseId" open="(" separator="," close=")"> #{item} </foreach> </select>
控制器部分:
if (listEarConclusion.size() != 0) { JSONArray json = new JSONArray(); /* * for (int i = listEarConclusion.size() - 1; i * >= 0; i--) { */ String empityArray[] = new String[0]; for (int i = 0; i < listEarConclusion.size(); i++) { JSONObject jo = new JSONObject(); jo.put("id", listEarConclusion.get(i).getId()); jo.put("member_id", listEarConclusion.get(i).getMember_id()); jo.put("name", listEarConclusion.get(i).getName()); jo.put("age", listEarConclusion.get(i).getAge()); jo.put("gender", listEarConclusion.get(i).getGender()); jo.put("phone", listEarConclusion.get(i).getPhone()); jo.put("xuewei", listEarConclusion.get(i).getXuewei()); jo.put("tongji", listEarConclusion.get(i).getTongji()); String earDiseaseId = listEarConclusion.get(i).getJibing_id(); String[] earDiseaseId1 = StringUtils.split(earDiseaseId, ",");// String if (earDiseaseId1.length != 0) { int[] earDiseaseId2 = new int[earDiseaseId1.length];// String陣列轉int陣列 for (int i1 = 0; i1 < earDiseaseId2.length; i1++) { earDiseaseId2[i1] = Integer.parseInt(earDiseaseId1[i1]); } Map<String, Object> map1 = new HashMap<String, Object>(); map1.put("earDiseaseId", earDiseaseId2); List<Object> listED = commonDiseaseService.findEDById(map1); jo.put("listED", listED); }else{ jo.put("listED", empityArray); } jo.put("record_time", f.format(listEarConclusion.get(i).getRecord_time())); json.add(jo); } result.put("res", "1001"); result.put("listEarConclusion", json); OutputUtil.outPutJsonObject(response, result); }