简体   繁体   English

通过Spring @RequestParam表示多个排序

[英]Representing multiple ordering through Spring @RequestParam

My Application currently serves requests for data, and can order the data to the users requirements, using RequestParams 我的应用程序当前正在处理数据请求,并可以使用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? 在代码方面,这很容易(使用Google集合进行救援),但是我如何将其公开给调用该服务的用户?

Ideally, I wouldn't want multiple orderBy @RequestParams (orderBy2, orderBy3, orderBy4) , as that's just plain ugly. 理想情况下,我不想要多个orderBy @RequestParams(orderBy2,orderBy3,orderBy4),因为这很丑陋。

Thoughts? 有什么想法吗?

Cheers 干杯

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,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM