P
P
piatachki2018-04-04 12:03:26
Java
piatachki, 2018-04-04 12:03:26

How to apply @PostFilter when returning ModelAndView?

Hello!
The @PostFilter annotation allows you to filter the elements of the returned collection through filterObject. This is good for RestController:

@RequestMapping(method = RequestMethod.GET)
    @PostFilter("filterObject.owner.email == authentication.name")
    public Collection<Club> getEntities(){
        return entityService.getEntities();
    }

Can you please tell me how to apply it if ModelAndView is returned with an attribute with a collection? filterObject is not available in SPeL this time, because the collection is returned directly, but inside the model:
@RequestMapping(method = RequestMethod.GET)
    @PostFilter("??? filterObject.owner.email == authentication.name")
    public String getEntities(Model model) {
        model.addAttribute("entities", entityService.getEntities());
        return "tamplate";
    }

Or, if this is not possible, maybe there is some kind of workaround? Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-04-04
@piatachki

You can simply annotate not a controller method, but a service method.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question