-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[疑问] 因为要进行联表查询,请问一下怎么实现分页自定义sql? #212
Comments
Test 里的用法似乎是 4.0.16-SNAPSHOT 版本才有的,4.0.15可以直接升级吗?项目已在生产环境运行了 |
按理说可以,你可以先本地试一试。 |
okok,多谢大佬 |
这边测试了下,暂时没发现什么问题,请问下 4.0.16 release 版本的发布计划是什么时间 |
暂时还没有具体时间。 |
明白了,多谢! |
@zhou-hao 大佬,发现一个问题,使用 怀疑是驼峰的问题,非驼峰的字段我看有值 |
完整sql看一下, 原始sql和日志中执行的sql。 |
日志里捞出来的 select
j_0."ota_id" as "xxx.otaId",
alarm_record."source_id" as "all_1.sourceId",
alarm_record."target_name" as "all_1.targetName",
alarm_record."handle_time" as "all_1.handleTime",
alarm_record."target_id" as "all_1.targetId",
alarm_record."level" as "all_1.level",
alarm_record."alarm_time" as "all_1.alarmTime",
alarm_record."description" as "all_1.description",
alarm_record."alarm_name" as "all_1.alarmName",
alarm_record."target_type" as "all_1.targetType",
alarm_record."target_key" as "all_1.targetKey",
alarm_record."alarm_config_id" as "all_1.alarmConfigId",
alarm_record."source_type" as "all_1.sourceType",
alarm_record."id" as "all_1.id",
alarm_record."source_name" as "all_1.sourceName",
alarm_record."state" as "all_1.state",
alarm_record."business_type" as "all_1.businessType"
from public.alarm_record alarm_record
left join public.xxx j_0 on j_0."device_id" = alarm_record."target_id"
where alarm_record."state" = 'normal'
limit 10 offset 0; 手写sql方式查询用的sql select * from alarm_record alarm_record " +
"left join xxx xxx on xxx.device_id = alarm_record.target_id 表名我因为保密原因,我替换成xxx了 |
实体类结构看一下 |
lambda方式是怎么写的 |
实体类,Xxx 子类字段正常接收 public class AlarmRecordDTO extends GenericEntity<String> {
@Column
@Schema(description = "告警配置ID")
private String alarmConfigId;
@Schema(description = "告警配置名称")
private String alarmName;
@Schema(description = "告警目标类型")
private String targetType;
@Schema(description = "告警目标Id")
private String targetId;
@Schema(description = "告警目标Key")
private String targetKey;
@Schema(description = "告警目标名称")
private String targetName;
@Schema(description = "告警源类型")
private String sourceType;
@Schema(description = "告警源Id")
private String sourceId;
@Schema(description = "告警源名称")
private String sourceName;
@Schema(description = "最近一次告警时间")
private Long alarmTime;
@Schema(description = "处理时间")
private Long handleTime;
@Schema(description = "告警级别")
private Integer level;
@Schema(description = "告警记录状态")
@EnumCodec
@ColumnType(javaType = String.class)
@DefaultValue("normal")
private AlarmRecordState state;
@Schema(description = "说明")
private String description;
@Column
@Schema(description = "业务告警类型")
private String businessType;
@Schema(description = "xxx信息")
private Xxx xxx;
} lambda return queryHelper
.select(AlarmRecordDTO.class)
.all(Xxx.class, AlarmRecordDTO::setXxx)
.all(AlarmRecordEntity.class)
.from(AlarmRecordEntity.class)
.leftJoin(Xxx.class, join -> join.is(Xxx::getDeviceId, AlarmRecordEntity::getTargetId))
.where(query)
.fetchPaged(); |
应该是bug。reimport一下maven再试试 |
试了下,可以了,大佬🐂啤 |
关联表我只想查固定几个字段,lambda 可以写么? |
|
多谢多谢 |
大佬,lambda 模式,分页情况下下,count 的sql,带了order条件,导致sql报错,使用的是 postgresql
select count(1) as "_total" from public.alarm_record alarm_record left join public.xxx j_0 on j_0."device_id" = alarm_record."target_id" where j_0."organization_id" = '1637633705471975424' order by alarm_record."alarm_time" desc limit 10 offset 0 |
好的,我看一下,应该是count条件构造的问题。 |
在reimport一下maven试试 |
可以了,不过我看控制台好像不打印 count 的 sql 了,是我的问题么 |
最新的sql日志名做出了调整。日志名 默认是实体类名了。 |
我调整下日志级别试试 |
似乎不对啊,select 的日志还是 R2dbcReactiveSqlExecutor 打印的,难道是只调整了 count 的 |
调整了下日志级别,可以看到 count 的日志了,是用来接收查询结构的实体类打印的 |
环境
java: 1.8.0_131
hsweb: 4.0.15
问题说明
因为要进行联表查询,请问一下怎么实现分页自定义sql
The text was updated successfully, but these errors were encountered: