带有 "param" 参数的 @RequestMapping 无法正常工作

@RequestMapping with "param" parameter not working correctly

我有以下 spring-boot REST 控制器:

@RestController
@AllArgsConstructor
public class AuditRecordArchivalHistoryController {
  private final AuditRecordArchivalHistoryService auditRecordArchivalHistoryService;

  @RequestMapping(value = "/archives", params = "pageNumber")
  public Mono<Slice<AuditRecordArchivalHistory>> findRecordsForAllTenants(
        @RequestParam (defaultValue = "0") Integer pageNumber)
    return 
      auditRecordArchivalHistoryService.findAllAuditRecordArchivalHistoryRecords(
            getPageable(pageNumber)
    );
}

@RequestMapping(value = "/archives", params = {"tenantId, pageNumber"} )
public Mono<Slice<AuditRecordArchivalHistory>> findRecordsForTenant(
        @RequestParam String tenantId,
        @RequestParam Integer pageNumber) {

    return 
      auditRecordArchivalHistoryService.findAuditRecordArchivalHistoryByTenantId(
            tenantId, getPageable(pageNumber)
    );
}

我希望如果我访问 URL

/archives?pageNumber=1

将调用方法:findRecordForAllTenants()。

而我在访问 URL

时的期望
/archives?tenantId=abc&pageNumber=1

是否会调用方法:findRecordsForTenant()。

但是,在这两种情况下,都会调用 findRecordsForAllTenants() 方法。我错过了什么吗?

桅杆像:

@RequestMapping(value = "/archives")
  public Mono<Slice<AuditRecordArchivalHistory>> findRecordsForAllTenants(
        @RequestParam (name="pageNumber", defaultValue = "0") Integer pageNumber)
    return 
      auditRecordArchivalHistoryService.findAllAuditRecordArchivalHistoryRecords(
            getPageable(pageNumber)
    );

我觉得这个问题是因为params里面的参数写错了,你可以对比一下我下面写的

@RequestMapping(value = "/archives", params = {"tenantId", "pageNumber"} )
public Mono<Slice<AuditRecordArchivalHistory>> findRecordsForTenant(
    @RequestParam String tenantId,
    @RequestParam Integer pageNumber) {
return auditRecordArchivalHistoryService.findAuditRecordArchivalHistoryByTenantId(
        tenantId, getPageable(pageNumber));
}

你输入了“tenantId,pageNumber”,应该是“tenantId”,“pageNumber”。 您缺少引号。