最近做项目要实现一个这样的效果,然后要统计数量。思路:用组查询
guorp by 然后返回,返回结果犯难了,最后通过万能的百度了解
// 返回实体类
public class TypeNum implements Serializable {
private Integer record;
private String name;
}
// 映射文件
<resultMap id="types" type="com.kang.blog.entity.vo.TypeNum">
<result column="count(b.typeid)" property="record"/>
<result column="name" property="name"/>
</resultMap>
// 代码
<select id="getTypeNum" resultMap="types">
select count(b.typeid),t.name from blog b left join type t on b.typeid = t.id GROUP BY b.typeid
</select>