[size=medium][b][color=blue]近日发现HQL中, count()函数要求还比较严格,举例说:[/color][/b]
[/size]
[b]1、count(1)报错[/b]
[b]2、count(c.*)报错[/b]
[b]3、count(*)正确[/b]
[/size]
[b]1、count(1)报错[/b]
<query name="getRecordCountById">
select count(1) as recordCount from Km c
where c.id=:id
</query>
[b]2、count(c.*)报错[/b]
<query name="getRecordCountById">
select count(c.*) as recordCount from Km c
where c.id=:id
</query>
[b]3、count(*)正确[/b]
<query name="getRecordCountById">
select count(*) as recordCount from Km c
where c.id=:id
</query>
本文详细解析了HQL中count()函数的使用规范,包括常见错误及其原因分析,通过三个实例展示了正确的使用方式,帮助开发者避免常见的编程陷阱。
1744

被折叠的 条评论
为什么被折叠?



