Use case for Pagination of Embedded resources

ⅰ亾dé卋堺 提交于 2019-11-29 08:17:32
fortm

Finally I am able to get my desired results and am posting here for all SDR users. I wanted to have pagination in this URL - where User -> One To Many -> UserLanguages

/users/{id}/userLanguages

Now Using default SDR configuration, embedded resources don't get paginated and therefore I have to manually expose them and the Workaround is as below which still takes very less lines of code -

@RestController
public class MainController {

    @RequestMapping(value = "/users/{id}/userLanguages", method = RequestMethod.GET)
    @PreAuthorize("permitAll")
    public ModelAndView findUserLanguages(@PathVariable Integer id) {
        ModelAndView model = new ModelAndView("forward:/userLanguages/search/findByUserId?userId=" + id);
        return model;
    }

then, in UserLangRepository

public interface UserLanguageRepository extends BaseRepository<UserLanguage, Integer> {

    Page<UserLanguage> findByUserId(@Param("userId") Integer userId, Pageable pageable);
}

Here name findByUserId follows Spring Data Query Derivation rule where there is user column in UserLanguage and id column in User. Then following URL is paginated and have other options as well like sort, size etc..

http://localhost:8585/MYAPP/users/3/userLanguages

There is an issue however that next and prev links point to forwarded link..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!