How to set IgnoreCase for collation from http request in Spring Boot 1.4

I have a Spring host to boot and accept HTTP requests.

Example: http://www.myserver.com/devices/

I am using Pageable to handle requests and automatic pagination and sorting, so I can use requests like: http://www.myserver.com/devices?sort=name,desc

However, there is a problem that the sorting if case is case sensitive and therefore the desired result of the sort (case insensitive sort) fails.

I know that "Pageable Sort" takes two arguments for the sort attribute, ie sort = name, desc, but when checking the debugger, I see that the objects for sorting the objects being sorted contain the ignoreCase attribute.

Here is a code snippet for a method that is called via REST:

public class DeviceController {

    @Autowired
    DeviceViewRepository deviceViewRepository;

    @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public Page<DeviceView> getAllDevices(@PageableDefault(page = 0, size = 10, sort= "id") Pageable pageable) {
        try {
            return deviceViewRepository.findAll(pageable);
        } catch (Exception e){
            throw e;
        }
    }
}

      

Is there a way to set this automatically / manually using the request url, PageableDefault or any other method?

Be aware that the collations are dynamic and the method in question uses the findAll () method of the Spring data repository.

UPDATE:

I found a similar problem here: Spring MVC: How to get case insensitive order from Pageable

This is what I am striving for. I can't comment there to ask how this was done or for advice, so if anyone knows how to implement this solution I'd really like to nudge you in the right direction.

+1


source to share


1 answer


The answer is (unfortunately) that you have to handle it yourself with a resolver - at least until https://jira.spring.io/browse/DATACMNS-658 is resolved, as per the answer to the post Spring MVC: how to get case insensitive order from a page .

It's relatively easy to get your own ArgumentResolver

to call, parse the url, and update the Sort object. The challenge for me was to make sure my paging control was always using the correct url and I had to do quite a lot of url manipulation which I thought I didn't need, although I'm new to Spring, so maybe I didn't do it too well.



I'm happy to provide my own implementation to give you a headgear, but I don't have anywhere else where I can upload files that stay there for a while. I would hate to post a link here (like Dropbox) that won't be there in 12 months when someone reads this post again.

We are happy to provide PM and someone else to publish them publicly if they have the means.

0


source







All Articles