0

The client sends some data in one request param like:

example.com/test?myparam=some123data

I would like to convert myparam into several other params and call a necessary controller with such parameters. Like this one:

@RequestMapping(value = "/test")
public @ResponseBody MyObject test(
    @RequestParam(value = "prefix") String prefix, // some
    @RequestParam(value = "number") int number, // 123
    @RequestParam(value = "suffix") String suffix)  //data
{ ... }

It is possible to put some custom converter for such situation?

2 Answers 2

2

I'm not really sure if it can be made wit request params. Instead, you could use path variables with regular expressions in the following way:

@RequestMapping(value = "/test/{prefix:[a-z]+}{number:[0-9]+}{suffix:[a-z]+}")
public @ResponseBody MyObject test(
    @PathVariable(value = "prefix") String prefix, // some
    @PathVariable(value = "number") int number, // 123
    @PathVariable(value = "suffix") String suffix)  //data
{ ... }

In this case your request URL will look like this:

example.com/test/some123data
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your solution! Your method solves the problem above but I will leave the question open because I need a little bit more logic here than regex.
0

You can try to implement your own argument resolver, here an example

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.