JpaRepository 接口中的分页方法 findAll(pageable) 查询无结果集 求指点!!!!!!!!!!!!
-------controller中的代start-------@RequestMapping(value="/pages/system/getUsersBypagina...
-------controller中的代 start-------
@RequestMapping(value = "/pages/system/getUsersBypagination.do")
@ResponseBody
public Page<Users> getUsersBypagination(int pageNumber, int pageSize) {
Pageable pageable = new PageRequest(pageNumber, pageSize);
return usersService.findBypagination(pageable);
}
-------controller中的代 end-------
-------serivce中的代 start-------
@Service
public class UsersSerciceImp implements UsersService {
@Autowired
private UsersDao usersDao;
@Override
public Page<Users> findBypagination(Pageable pageable) {
Page<Users> pageUsers = usersDao.findAll(pageable);
return pageUsers;
}
}
-------serivce中的代 end-------
-------userdao中的代 start-------
public interface UsersDao extends JpaRepository<Users, Long> {
public List<Users> findByusername(String username);
}
-------userdao中的代 end-------
查询结果:中content 为空 展开
@RequestMapping(value = "/pages/system/getUsersBypagination.do")
@ResponseBody
public Page<Users> getUsersBypagination(int pageNumber, int pageSize) {
Pageable pageable = new PageRequest(pageNumber, pageSize);
return usersService.findBypagination(pageable);
}
-------controller中的代 end-------
-------serivce中的代 start-------
@Service
public class UsersSerciceImp implements UsersService {
@Autowired
private UsersDao usersDao;
@Override
public Page<Users> findBypagination(Pageable pageable) {
Page<Users> pageUsers = usersDao.findAll(pageable);
return pageUsers;
}
}
-------serivce中的代 end-------
-------userdao中的代 start-------
public interface UsersDao extends JpaRepository<Users, Long> {
public List<Users> findByusername(String username);
}
-------userdao中的代 end-------
查询结果:中content 为空 展开
2个回答
推荐于2018-02-23
展开全部
public Page<Task> getUserTask(Long userId, Map<String, Object> searchParams, int pageNumber, int pageSize,
String sortType) {
PageRequest pageRequest = buildPageRequest(pageNumber, pageSize, sortType);
Specification<Task> spec = buildSpecification(userId, searchParams);
return taskDao.findAll(spec, pageRequest);
}
/**
* 创建分页请求.
*/
private PageRequest buildPageRequest(int pageNumber, int pagzSize, String sortType) {
Sort sort = null;
if ("auto".equals(sortType)) {
sort = new Sort(Direction.DESC, "id");
} else if ("title".equals(sortType)) {
sort = new Sort(Direction.ASC, "title");
}
return new PageRequest(pageNumber - 1, pagzSize, sort);
}
/**
* 创建动态查询条件组合.
*/
private Specification<Task> buildSpecification(Long userId, Map<String, Object> searchParams) {
Map<String, SearchFilter> filters = SearchFilter.parse(searchParams);
filters.put("user.id", new SearchFilter("user.id", Operator.EQ, userId));
Specification<Task> spec = DynamicSpecifications.bySearchFilter(filters.values(), Task.class);
return spec;
}
Storm代理
2023-08-29 广告
2023-08-29 广告
StormProxies是全球大数据IP资源服务商,其住宅代理网络由真实的家庭住宅IP组成,可为企业或个人提供满足各种场景的代理产品。点击免费测试(注册即送1G流量)StormProxies有哪些优势?1、IP+端口提取形式,不限带宽,IP...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询