Issue
I have the following spring-boot REST Controller:
@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)
);
}
I expect that if I access the URL
/archives?pageNumber=1
the method: findRecordForAllTenants() would be called.
Whereas my expectation upon accessing the URL
/archives?tenantId=abc&pageNumber=1
is that the method: findRecordsForTenant() would be called.
However, in both the cases, the method findRecordsForAllTenants() is being called. Am I missing something?
Solution
I think this problem is because the parameters in params are written wrong, you can compare to what I wrote below.
@RequestMapping(value = "/archives", params = {"tenantId", "pageNumber"} )
public Mono<Slice<AuditRecordArchivalHistory>> findRecordsForTenant(
@RequestParam String tenantId,
@RequestParam Integer pageNumber) {
return auditRecordArchivalHistoryService.findAuditRecordArchivalHistoryByTenantId(
tenantId, getPageable(pageNumber));
}
Answered By - 白天明
Answer Checked By - Marilyn (JavaFixing Volunteer)