mysql - mybatis 查询 统计某个列数量 ,根据一个列,分组查询,在xml文件如何接收
问题描述
mybatis 查询 统计某个列数量 ,根据一个列,分组查询,在xml文件中resultType参数不知道怎么写。
SQL语句:
select title_type,COUNT(title) from qa_title where title like '%车%' GROUP BY title_type ;
xml:
<select id="getTitleCuntLike" resultType="cheng.secondprice.entitylet.QaContent" parameterType="String">
select title_type,COUNT(title) from qa_title where title like '%${titles}%' GROUP BY title_type
</select>
试过用实体类去接收,不行,想问问这种情况,resultType参数该怎么写才能接收到值
在实体,定义一个变量用来接收 count()查询出来的值。
public class Bean {
private ....;
private Integer count; //新增一个实体属性,接受查询的值
}
xml文件:
<resultMap id="Map" type="cheng.secondprice.entitylet.QaContent">
<id></id>
....
<!--在这里映射要查询的列,只要定义实体就行了,不用映射到数据库表的列-->
<result property="count" />
</resultMap>
<!--resultType 改成 resulyMap-->
<select id="getTitleCuntLike" resulyMap="Map" parameterType="String">
select title_type,COUNT(title) count from qa_title where title like '%${titles}%' GROUP BY title_type
</select>
谢谢你们的答案,这是整理出来的代码,有什么不对,不清楚的地方还请大家提问,
这篇关于mysql - mybatis 查询 统计某个列数量 ,根据一个列,分组查询,在xml文件如何接收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!