mybatis sql返回多个参数

最近做项目的时候碰到一个问题,查询一个表单,返回多个字段和函数计算的值,对于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>

成功解决。

   

时间: 2024-08-03 02:20:40

mybatis sql返回多个参数的相关文章

c# 查询sql 返回多个参数

1.根据需要查询mysql 语句,返回三个需要的参数,不是数据集 2.编写函数如下: public static void GetParas(string 条件1, out string 返回值1, out string 返回值2, out string 返回值3) { 返回值1= string.Empty; 返回值2= string.Empty; 返回值3= string.Empty; string strSQL = string.Format("Select * from 表 where 字

mybatis mapper文件sql语句传入hashmap参数

1.怎样在mybatis mapper文件sql语句传入hashmap参数? 答:直接这样写map就可以 <select id="selectTeacher" parameterType="Map" resultType="com.myapp.domain.Teacher"> select * from Teacher where c_id=#{id} and sex=#{sex} </select>

mybatis 参数为list时,校验list是否为空, mybatis ${}与#{}的区别,Mybatis sql in

1.mybatis 参数为list时,校验list是否为空 2. mybatis ${}与#{}的区别 简单来说#{} 解析的是占位符?可以防止SQL注入, 比如打印出来的语句 select * from table where id=? 然而${} 则是不能防止SQL注入打印出来的语句 select * from table where id=2 实实在在的参数. 最简单的区别就是${}解析穿过来的参数值不带单引号,#{}解析传过来参数带单引号. 最后总结一下必须使用$引用参数的情况,那就是参

Mybatis——SQL语句构建器类

SQL语句构建器类 问题 Java程序员面对的最痛苦的事情之一就是在Java代码中嵌入SQL语句.这么来做通常是由于SQL语句需要动态来生成-否则可以将它们放到外部文件或者存储过程中.正如你已经看到的那样,MyBatis在它的XML映射特性中有一个强大的动态SQL生成方案.但有时在Java代码内部创建SQL语句也是必要的.此时,MyBatis有另外一个特性可以帮到你,在减少典型的加号,引号,新行,格式化问题和嵌入条件来处理多余的逗号或 AND 连接词之前.事实上,在Java代码中来动态生成SQL

mybatis sql注入安全

1.mybatis语句 SELECT * FROM console_operator WHERE login_name=#{loginName} AND login_pwd=#{loginPwd} 2.日志打印信息正确情况:username:admin, password:admin 2014-07-30 10:39:10,646 DEBUG [http-bio-8080-exec-9] com.autoyolConsole.mapper.OperatorMapper.login.BaseJdb

spring mvc 配置 mybatis sql拦截器

直接上代码: mybatis配置中 添加  <property name="plugins"> 如下: <bean id="sqlSessionFactory" class="com.hotent.core.mybatis.SqlSessionFactoryFactoryBean"> <property name="configLocation" value="classpath:/co

Mybatis 学习---${ }与#{ }获取输入参数的区别、Foreach的用法

一.Mybatis中用#{}和${}获取输入参数的区别 1."#{}"和"${}"都可以从接口输入中的map对象或者pojo对象中获取输入的参数值.例如 1 <mapper namespace="com.hh.dao.UserDao"> 2 <select id="selectByIdList" resultType="com.hh.domain.SysUser"> 3 select

SqlServer 获得存储过程的返回值(参数返回),别玩了output

declare @dingdanid int declare @fanhuizhi int set @dingdanid = 1 exec 检测订单出库资格 @dingdanid ,@fanhuizhi output   (注意别忘了output否则返回值是NULL) select @fanhuizhi create proc dbo.检测订单出库资格 @dingdanID int,     @returnValue int output as -- 输入变量 订单编号 set @returnV

以函数返回值做参数时,函数调用的顺序

环境:vs2013 在下面的代码中 1 //类似于下面的代码 2 3 foo(char*,char*,char*); 4 5 char* str ="A#B#C"; 6 7 foo(strtok(str,"#"),strtok(NULL,"#"),strtok(NULL,"#")); 预计让函数foo得到("A","B","C")的参数,程序编译的时候没问题,但是运行