Skip to content

linkTo_methodOn not working on GET requested object parameter #496

@khong07

Description

@khong07

Suppose we have this method

@RequestMapping(value= "list")
public HttpEntity<ListResource> getList(
        @RequestParam(value = "text1", required = false) String text1,
        @RequestParam(value = "text2", required = false) String text2,
        @RequestParam(value = "text3", required = false) String text3,
        ...
        @RequestParam(value = "page", defaultValue = "1") Integer page,
        @RequestParam(value = "limit", defaultValue = "10") Integer limit) {
    // ...
}

Because we have a lot of parameters, we rewrote

@RequestMapping(value= "list")
public HttpEntity<ListResource> getList(RequestObject requestObject) {
    // ...
}

public class RequestObject {
    private String text1;
    private String text2;
    private String text3;
    ...
    private Integer page;
    private Integer limit;
}

Spring MVC maps automatically the RequestObject with given parameters

But when generating the Link

final RequestObject requestObject = new RequestObject();
requestObject.setPage(1);
requestObject.setLimit(10);
requestObject.setText1("test");
return ControllerLinkBuilder.linkTo(ControllerLinkBuilder.methodOn(ABCController.class)
                .getList(requestObject));

That doesn't return

http://localhost:8080/list?page=1&limit=10&text1=test
but only
http://localhost:8080/list

do you have any idea?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions