我有一个 ArgumentResolver,我在其中定义了分页的后备情况:
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
PageableHandlerMethodArgumentResolver resolver = new PageableHandlerMethodArgumentResolver();
resolver.setFallbackPageable(new PageRequest(0, 5, Direction.DESC, "id"));
argumentResolvers.add(resolver);
}
}
这就是我的控制器方法的样子:
@RequestMapping(RequestMappings.SHOW_ALL_ITEMS)
public String showAllItems(Model model, Pageable pageable) {
PageWrapper<Item> page = new PageWrapper<Item>
(itemService.getAllItems(pageable), RequestMappings.SHOW_ALL_ITEMS);
model.addAttribute("page", page);
return ViewNamesHolder.SHOW_ALL_ITEMS;
}
如果我想要另一个具有不同回退情况的控制器方法怎么办?我知道我可以注册许多参数解析器对象。但是在这种情况下,我如何定义在控制器方法中使用哪一个呢?:
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
PageableHandlerMethodArgumentResolver resolverWithSizeFive = new PageableHandlerMethodArgumentResolver();
resolverWithSizeFive.setFallbackPageable(new PageRequest(0, 5, Direction.DESC, "id"));
argumentResolvers.add(resolverWithSizeFive);
PageableHandlerMethodArgumentResolver resolverWithSizeTen = new PageableHandlerMethodArgumentResolver();
resolverWithSizeTen.setFallbackPageable(new PageRequest(0, 10, Direction.DESC, "id"));
argumentResolvers.add(resolverWithSizeTen);
}
}