//应用业务场景: 你有一个商品表,每个商品都有可以替代的商品;当你点击一个商品详情的时候,要对应展示该商品所有可替代商品的的列表(个人所遇到的一些情况,特此记录,以备后用~~~)
xml文件:
<!--获取可替代商品信息--> <select id="getReplaceFixture" resultMap="BaseResultMap" parameterType="java.util.Map"> select id, code from fixture where id IN <foreach collection="fixtureId" item="item" index="index" separator="," open="(" close=")"> #{item,jdbcType=VARCHAR} </foreach> </select>dao层:
//可替代商品 List<Fixture> getReplaceFixture(Map<String, Object> map);serviceImpl层:
//获取可替代商品信息 String replaceFixtureIds = replaceFixtureMapper.getReplaceFixtureIds(fixture.getId()); if (null != replaceFixtureIds && !"".equals(replaceFixtureIds)) { Map<String, Object> map = new HashMap<>(); List<String> params = new ArrayList<>(); for (String id : replaceFixtureIds.split(",")) { params.add(id); } if (params.size() > 0) { map.put("fixtureId", params); List<Fixture> fixtureList = fixtureMapper.getReplaceFixture(map); fixture.setReplaceFixtureList(fixtureList); } }注意: service实现层map的key为"fixtureId"与xml层中collection的值是对应的,要保持一致