Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Representing multiple ordering through Spring @RequestParam

My Application currently serves requests for data, and can order the data to the users requirements, using RequestParams

@RequestParam(value = "orderBy", required = false, defaultValue = "severity") String orderBy,
@RequestParam(value = "order", required = false, defaultValue = "desc") String order,

You get the idea.

However, I want to implement multi sorting, (ordering by severity, then matching severities are ordered by date). Code wise, this is easy (google-collections to the rescue), but how would I expose this to the user calling the service?

Ideally, I wouldn't want multiple orderBy @RequestParams (orderBy2, orderBy3, orderBy4) , as that's just plain ugly.

Thoughts?

Cheers

like image 378
Ben Davies Avatar asked Jul 15 '26 07:07

Ben Davies


1 Answers

Usually you should be able to just turn your request param into an array like:

@RequestParam(value = "orderBy", required = false, defaultValue = "severity") String[] orderBy,
@RequestParam(value = "order", required = false, defaultValue = "desc") String[] order,
like image 191
Daff Avatar answered Jul 17 '26 20:07

Daff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!