12.2.1 数据层
一般一个表对应着一个类.
12.2.1.1 数据层的mapper
接口
import java.util.List;
import java.util.Map;
public interface OrderMapper {
/**
* 获取订单总的销售额
*
* @param date
* @return
*/
double getOrderAmountTotal(String date);
/**
* 获取每小时的销售额明细
*
* @param date
* @return
*/
List<Map> getOrderAmountHour(String date);
}
12.2.1.2 数据层的 sql
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper SYSTEM "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<!--namespace 对应前面定义的接口-->
<mapper namespace="com.atguigu.gmall0225publisher2.mapper.OrderMapper">
<!--对应前面接口中的方法, 标签内写响应的查询语句, 查询的接口会赋值给这个方法的返回值-->
<select id="getOrderAmountTotal" resultType="java.lang.Double">
select sum(total_amount) sum from gmall_order_info where create_date=#{date}
</select>
<!--分时明细-->
<select id="getOrderAmountHour" resultMap="orderAmountHourList">
select create_hour, sum(total_amount) sum from gmall_order_info where create_date=#{date} group by create_hour
</select>
<resultMap id="orderAmountHourList" type="java.util.Map" autoMapping="true">
</resultMap>
</mapper>