I use the combination of linkTo(methodOn())
to generate links to my endpoint which works fine as long as i have the RequestParams as separate method arguments. When i move them into an DTO (because there are many…) the linkt just get generated without any params…
The Endpoint:
@GetMapping("/search")
fun searchByIds(
params: SearchIdsParameterDto
): ResponseEntity<SearchEntriesDto> {
// some code...
}
The DTO:
data class SearchByIdsParameterDto(
@RequestParam()
var subIds: String,
@RequestParam()
@Min(0)
var start: Int?,
@RequestParam()
@Min(1)
var limit: Int? = 20,
): RepresentationModel<SearchByIdsParameterDto>()
And this is how i want to generate the link:
private fun searchLink(
rel: LinkRelation,
params: SearchParameter,
start: Int,
limit: Int
): Link {
val link = linkTo(
methodOn(SearchCtl::class.java)
.searchByIds(
SearchByIdsParameterDto(
subOutletIDs,
start,
limit
)
)
).withRel(rel)
// other than "self" this method is used for pagination links (first, next etc)
// these links are expanded as is to remove templates
return when (rel) {
SELF -> link
else -> link.expand()
}
}
With that, the link gets generated but without any parameters in it.