<resultMap class="Category" id="categoryAndInfoResult" groupBy="cid">
<result column="cid" property="cid"/>
<result column="cname" property="cname"/>
<result property="infos" resultMap="Category.infoResult"/>
</resultMap>
<resultMap class="java.util.HashMap" id="infoResult">
<result property="mid" column="mid"/>
<result property="mtitle" column="mtitle"/>
</resultMap>
<select id="getCategoryAndInfo" parameterClass="String" resultMap="categoryAndInfoResult">
select c.*, m.id mid, m.title mtitle from category c , classify_msg m where m.m_cid = c.cid and c.cid in ($value$)
</select>
上面就是一个N+1的解决方案。但现在我的问题在于,我查询的是同一个表 Category 。Category保存所有的类别,之间有“层级”的关系。我现在想要做的是,根据“级别”,比如:根据“一级栏目”查询,同时查询自对应的“二级栏目”。 <sqlMap namespace="Category"> <!-- 映射Category的结果集 -->
<resultMap class="Category" id="categoryResult">
<result column="cid" property="cid"/>
<result column="cname" property="cname"/>
<result column="cdesc" property="cdesc"/>
<result column="cgrade" property="cgrade"/>
<result column="cpid" property="cpid"/>
<result column="cpath" property="cpath"/>
</resultMap> <!-- 根据cids,查询类别,及其“子类” -->
<resultMap class="Category" id="categoryAndChildrenResult" groupBy="cid">
<result column="cid" property="cid"/>
<result column="cname" property="cname"/>
<result column="cdesc" property="cdesc"/>
<result column="cgrade" property="cgrade"/>
<result column="cpid" property="cpid"/>
<result column="cpath" property="cpath"/>
<result property="children" resultMap="Category.categoryResult"/>
</resultMap>
<select id="queryCategoryByCids" parameterClass="String" resultMap="categoryAndChildrenResult">
select * from category p left join category c on p.cid = c.cpid where p.cid in ($value$)
</select>
结果:但结果始终不对。只是“父级栏目”的信息。可是没有找到错误的地方?请大家指点下!谢谢
解决方案 »
- 如何使用solr配置来建立多张表的索引?
- 我要用<C:IF>判断 ${XX} 和 '留言' 是不是相等 应该怎么做?在线等,急啊
- 为什么 axis2 生产webservice的客户端的中几乎都没有CallbackHandler和stub了?
- 菜鸟发问:请问对象持久化有什么好处,为什么要进行持久化?
- 向高手请教hibernate
- struts 文件上传成功之后的问题
- Struts中Action是怎么实现映射的
- struts 中index.jsp中就从数据库中读取数据显示出来,那如何让index.jsp先执行IndexAction呢?
- java.rmi(这个rmi是什么的缩写?)
- ★★谁有JB7+WebSphere开发环境配置说明,100分送上!!
- 在线求助高手java书籍问题
- js怪问题,js图片切换在ie7中不显示,在ie6中正常显示
建议对sql优化!
把*换成具体的列例如c.cid