在开发中遇到这样的问题:前端展示的时候,需要展示'日访问速率'。日访问速率=日访问量/(24*3600),数据库中存在日访问量,而不存在日访问速率。 在ibatis的做查询排序的时候,需要新的domain、修改sql。这个时候,ibatis的extends发挥了用处。
代码如下:增加sumNumDayAverage字段
- public class HummockClientStatExt extends HummockClientStat {
- private static final long serialVersionUID = 3307034127892719406L;
- private double sumNumDayAverage;
- public double getSumNumDayAverage() {
- return sumNumDayAverage;
- }
- public void setSumNumDayAverage(double sumNumDayAverage) {
- this.sumNumDayAverage = sumNumDayAverage;
- }
- /*
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "HummockClientStatExt [sumNumDayAverage=" + sumNumDayAverage + super.toString()
- + "]";
- }
- }
ibatis的extends用法如下:extends="HummockClientStatResult"
- <resultMap id="HummockClientStatExtResult"
- class="com.alibaba.hummock.console.model.HummockClientStatExt" extends="HummockClientStatResult">
- <result property="sumNumDayAverage" column="sum_Num_Day_Average" />
- </resultMap>
- <parameterMap class="java.util.Map" id="paramQueryMap">
- <parameter property="appId" />
- <parameter property="listValue" />
- <parameter property="sort" />
- <parameter property="dir" />
- <parameter property="begin" />
- <parameter property="increment" />
- </parameterMap>
- <select id="getClientStat" resultMap="HummockClientStatExtResult"
- parameterMap="paramQueryMap">
- SELECT
- <include refid="columns" />, sum_Num/(24*3600) as sum_Num_Day_Average
- <![CDATA[
- FROM client_stat
- ]]>
- <dynamic prepend="where">
- <isNotEmpty prepend="and" property="appId">
- app_Id = #appId#
- </isNotEmpty>
- <isNotEmpty prepend="and" property="listValue">
- list_value =
- #listValue#
- </isNotEmpty>
- <isNotEmpty prepend="order by" property="sort">
- $sort$ $dir$
- </isNotEmpty>
- </dynamic>
- limit #begin#,#increment#
- </select>