码迷,mamicode.com
首页 > 数据库 > 详细

mybatis sql返回多个参数

时间:2016-11-14 12:36:25      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:null   目的   test   start   line   定义   tar   com   mybatis   

  最近做项目的时候碰到一个问题,查询一个表单,返回多个字段和函数计算的值,对于mybatis来说返回类型就不好定义了,想了半天,查了很多的资料,

最后成功解决问题,下面详细介绍一下。

一 需求分析

  计算当天所有的评价人数,评价分数,评价次数,表的结构如下:

  技术分享

 

二 实现

  定义一个返回类:

  public class SellerAllEvalPo {

    private Integer totalScore;
private Integer totalEval;
private Integer totalPeople;

public Integer getTotalScore() {
return totalScore;
}

public void setTotalScore(Integer totalScore) {
this.totalScore = totalScore;
}

public Integer getTotalEval() {
return totalEval;
}

public void setTotalEval(Integer totalEval) {
this.totalEval = totalEval;
}

public Integer getTotalPeople() {
return totalPeople;
}

public void setTotalPeople(Integer totalPeople) {
this.totalPeople = totalPeople;
}

}

  sql语句:

    <select id="getSellerAllScore" resultType="SellerAllEvalPo"> 

    select sum(eval_num) as total_eval, sum(total_score) as total_score from seller_eval_day

    <where>      

    <if test="startTime != null">

        and business_day &gt;= #{startTime}
  </if>
  <if test="endTime != null">
  and business_day &lt;= #{endTime}
  </if>
  <if test="sellerId != null">
   and seller_id = #{sellerId}
  </if>
  </where>
  </select>

成功解决。

   

 

mybatis sql返回多个参数

标签:null   目的   test   start   line   定义   tar   com   mybatis   

原文地址:http://www.cnblogs.com/wangpenglen/p/6061025.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!