现在在做ks,然后需要实现文章评论一起显示到页面上,我想的是一对多查询显示,网上的例子都试过了,总是会有一些问题,写过一个基于MyBaits的一对多查询,但是我换成基于SSM的就转不过弯来了,zy太多了,有时候弄不出来真的很浪费时间😭
其实不必追求一对多查询的,你就可以先查出文章,再查询评论,因为这个评论一般都要分页,一对多查询很难搞定分页而且sql也麻烦
<select id="getAddressListByUserId" resultMap="address"
parameterType="int">
SELECT u.*,a.id as
a_id,a.contact,a.addressDesc,a.postCode,a.tel
FROM smbms_user
u,smbms_address a where u.id=a.userId AND u.id=#{addressid}
</select>
<resultMap type="entity.User" id="address">
<id property="id" column="id" />
<result property="userCode" column="userCode" />
<result property="userName" column="userName" />
<!-- property属性名javaType属性类型column数据库字段名 -->
<collection property="addresses" javaType="entity.Address"
resultMap="addressResult" />
</resultMap>
很简单的无非就是返回的类型做一下处理
mongodb