背景
使用@TableField对别名不生效问题
代码
<select id="getMonthDevelopKeepList" resultType="org.zt.task.report.entity.gross.vo.MonthDevelopGrossData">
SELECT
bloc,
department,
develop_department,
is_performance,
IFNULL(SUM(real_income),0) as realIncome,
IFNULL(SUM(total_income),0) as totalIncomeFinal,
IFNULL(SUM(refund),0) as refundFinal,
IFNULL(SUM(commodity_cost),0) as commodityCostFinal,
IFNULL(SUM(platform_fee),0) as platformFeeFinal,
IFNULL(SUM(collection_fee),0) as collectionFeeFinal,
IFNULL(SUM(update_freight),0) as updateFreightFinal,
IFNULL(SUM(return_update_freight),0) as returnUpdateFreight,
IFNULL(SUM(update_freight_last),0) as updateFreightLastFinal,
IFNULL(SUM(packing_material_fee),0) as packingMaterialFeeFinal,
IFNULL(SUM(capital_cost),0) as capitalCostFinal,
IFNULL(SUM(publish_fee),0) as publishFeeFinal,
IFNULL(SUM(marketing_fee),0) as marketingFeeFinal,
IFNULL(SUM(scramble_fee),0) as scrambleFeeFinal,
IFNULL(SUM(cloud_host_vps),0) as cloudHostVpsFinal,
IFNULL(SUM(vps_and_others),0) as vpsAndOthersFinal,
IFNULL(SUM(fixed_service_fee_allocation),0) as fixedServiceFeeAllocationFinal,
IFNULL(SUM(other_payments),0) as otherPaymentsFinal,
IFNULL(SUM(fines_or_temporary_deductions),0) as finesOrTemporaryDeductionsFinal,
IFNULL(SUM(collection_fees_and_others),0) as collectionFeesAndOthersFinal,
IFNULL(SUM(service_charge),0) as serviceChargeFinal,
IFNULL(SUM(vat_fee),0) as vatFeeFinal,
IFNULL(SUM(month_undertake_amount),0) as monthUndertakeAmountSum,
IFNULL(SUM(profit_loss),0) as profitLossFinal,
IFNULL(SUM(month_clear_cost),0) as monthClearCostFinal,
IFNULL(SUM(destroy_cost),0) as destroyCostFinal,
IFNULL(SUM(gross_margin),0) as grossMargin,
IFNULL(SUM(warehouse_cost),0) as warehouseCostSum,
IFNULL(SUM(position_fee),0) as positionFeeFinal,
IFNULL(SUM(company_manpower_cost1),0) as companyManpowerCost1,
IFNULL(SUM(company_manpower_cost2),0) as companyManpowerCost2,
IFNULL(SUM(order_bill),0) as orderBillSum,
IFNULL(SUM(net_profit),0) as netProfit
FROM
month_develop_gross_data
WHERE
`month` = #{month}
GROUP BY
bloc,
department,
develop_department,
is_performance
</select>
如上,我有一堆sum字段需要起别名,我使用MonthDevelopGrossData作为承接类
一开始我用表字段做as别名,如下,使用@TableField注释映射
@TableField("company_manpower_cost1")
private BigDecimal companyManpowerCost1;
思考
发现是不生效的,所以判断@TableField对自己手写的sql as是不生效的。
网上百度有个老哥说只有使用mybatisPlus自己的语法调用sql,会生效。这个暂时还没有尝试。
建议
所以建议这种需要别名的就直接一步到位,用bean里面的属性名直接承接,不要玩花活了