我们平常库表字段一般都是英文的,标准也是这样,如果碰到中文的应该如何处理呢?库表如下
先把实体类改成属性字段改成英文
@ApiModelProperty(value = "付款方名称")
@TableField("付款方名称")
private String payName;
@ApiModelProperty(value = "付款条件")
@TableField("付款条件")
private String paymentClause;
//其他太长不贴了哈
自写SQL语句,对中文字段取别名,as 成实体类属性(付款方名称 as payName)
where跟的属性还是数据库的字段名
<select id="selectKeyAccountByCompanyCodeAndPayCode" parameterType="string" resultType="FinCommercialOnestopshop001Keyaccount">
select ID as id, [Index] as newIndex, 付款方代码 as payCode, 付款方名称 as payName, KAorEC as kaOrEc,
[BU(By Management)] as bu, CompanyCode as companyCode,
Company as company, 付款条件 as payClause, 城市 as city,
KACustomerGroup as kaCustomerGroup, 销售经理 as salesManager,
销售负责人 as directoSales, POA账龄 as poaBookAge
from Fin_Commercial_OneStopShop_001_KeyAccount
where
CompanyCode = #{companyCode}
and 付款方代码 = #{payCode};
</select>
Mapper方法
FinCommercialOnestopshop001Keyaccount selectKeyAccountByCompanyCodeAndPayCode(@Param("companyCode") String companyCode, @Param("payCode") String payCode);
问题:为什么where后面不能跟别名
sqlserver查询执行顺序是如下
- FROM JOIN ON
- WHERE ♥
- GROUP BY
- HAVING
- SELECT DISTINCT TOP() ♥
- ORDER BY
可以看到,在where执行的时候,还未执行select,别名也就还没生效,而order
by的时候select已经执行,所以已经存在
最后,还是建议用英文配合驼峰命名哈~