1.相应的xml文件中
<select id="selectByCategories" resultType="map" parameterType="java.lang.String" >
${_parameter}
</select>
2.对应的mapper文件中添加下列方法
List<Map<String , Long>> selectByCategories(String sql);
3.在业务层写相应的逻辑
// 得到不同分类下的相同文章 public List<ArticleInfo> getTheSameArticle(String args){ String[] arr = args.split(","); int len=arr.length; String sql="select article_id from" + " (select category_id,article_id from article_category WHERE category_id in ("+args + ") GROUP BY category_id,article_id)b GROUP BY article_id HAVING count(category_id)="+len; System.out.println(sql); List <Map<String, Long>> resultList=articleCategoryMapper.selectByCategories(sql ); System.out.println(resultList); LinkedList<ArticleInfo> articleList=new LinkedList<>(); for (int i=0;i<resultList.size();i++) { System.out.println(resultList.get(i)); Map<String, Long> tempMap = resultList.get(i); System.out.println(tempMap.get("article_id")); long id=tempMap.get("article_id"); articleList.add(getOneById(id)); } return articleList; }
成功。