All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.viiyue.plugins.mybatis.mapper.special.AggregateFunctionMapper Maven / Gradle / Ivy

Go to download

Mybatis generic mapper plugin for solving most basic operations, simplifying sql syntax and improving dynamic execution efficiency

There is a newer version: 1.3.7
Show newest version
/**
 * Copyright (C) 2017 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.viiyue.plugins.mybatis.mapper.special;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

import org.apache.ibatis.annotations.SelectProvider;

import com.viiyue.plugins.mybatis.annotation.mark.EnableResultMap;
import com.viiyue.plugins.mybatis.annotation.mark.Reference;
import com.viiyue.plugins.mybatis.condition.AggregateFunctionExample;
import com.viiyue.plugins.mybatis.condition.Example;
import com.viiyue.plugins.mybatis.mapper.Marker;
import com.viiyue.plugins.mybatis.provider.DynamicProvider;
import com.viiyue.plugins.mybatis.provider.base.BaseExampleProvider;

/**
 * 

Aggregate function api method interface definition * *

    *
  • max( ? ) - Calculate the maximum value of a column *
  • min( ? ) - Calculate the minimum value of a column *
  • avg( ? ) - Calculate the average of a column *
  • sum( ? ) - Get the total value of a single column *
  • count( ?|* ) - Returns the number of rows matching the specified criteria *
* * @author tangxbai * @since 1.1.0 * * @param database entity type * @param query data return entity type * @param primary key type, must be a {@link Serializable} implementation class. */ public interface AggregateFunctionMapper extends Marker { /** *

Query a single statistic through an aggregate function * *

	 * // The minimum value of the specified column
	 * Example.minimum( Bean.class, "propertyName" ).a().b();
	 * 
	 * // The maximum value of the specified column
	 * Example.maximum( Bean.class, "propertyName" ).a().b();
	 * 
	 * // The sum of the specified columns
	 * Example.summation( Bean.class, "propertyName" ).a().b();
	 * 
	 * // Average of the specified column
	 * Example.average( Bean.class, "propertyName" ).a().b();
	 * 
	 * // The number of rows in the specified column
	 * Example.count( Bean.class, "propertyName" ).a().b();
	 * Example.count( Bean.class, "*" ).a().b();
	 * 
* *

Note: Statistics single results cannot be used with {@code groupBy}. * If groupBy is used, the result may be different from your expectations. * *

WARNING: It is best not to use the {@code groupBy} function * * @param example the example object * @return the specified statistical result and uses {@link BigDecimal} to represent */ @Reference( method = "selectByExample" ) @SelectProvider( type = BaseExampleProvider.class, method = DynamicProvider.dynamicSQL ) BigDecimal selectStatisticByAggregateFunction( Example example ); /** *

Query a list of statistical results * *

	 * // The minimum value of the specified column
	 * Example.minimum( Bean.class, "propertyName1", "propertyName2", ... ).a().b();
	 * 
	 * // The maximum value of the specified column
	 * Example.maximum( Bean.class, "propertyName1", "propertyName2", ... ).a().b();
	 * 
	 * // The sum of the specified columns
	 * Example.summation( Bean.class, "propertyName1", "propertyName2", ... ).a().b();
	 * 
	 * // Average of the specified column
	 * Example.average( Bean.class, "propertyName1", "propertyName2", ... ).a().b();
	 * 
	 * // The number of rows in the specified column
	 * Example.count( Bean.class, "propertyName1", "propertyName2", ...  ).a().b();
	 * Example.count( Bean.class, "*", "propertyName1", "propertyName2", ...  ).totalAlias( "propertyName" ).a().b();
	 * Example.count( Bean.class, "*" ).totalAlias( "propertyName" ).a().b();
	 * 
* *

Note:

*

    *
  • If you call groupBy/orderBy/limit and so on, then don't call the when() condition method. *
  • If you want to use conditional functions and want to use groupBy/orderBy/limit, please use when() to access. *
* * @param example the example object * @return the list of statistical results */ @EnableResultMap @Reference( method = "selectByExample" ) @SelectProvider( type = BaseExampleProvider.class, method = DynamicProvider.dynamicSQL ) List selectStatisticListByAggregateFunction( Example example ); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy