Ctrl+F 搜索
update/delete 的话需要 加上@Modifying 注解
update 加上事务 @Transactional
查询自定义内容,使用原生sql语句 需要加 nativeQuery = true
分页的serviceImpl
@Override
public List<User> list(final User user, Integer page, Integer pageSize, Direction direction, String... properties) {
Pageable pageable=new PageRequest(page-1, pageSize, direction,properties);
Page<User> pageUser=userRepository.findAll(new Specification<User>() {
@Override
public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
Predicate predicate=cb.conjunction();
if(user!=null){
if(StringUtil.isNotEmpty(user.getUserName())){
predicate.getExpressions().add(cb.like(root.<String>get("userName"), "%"+user.getUserName().trim()+"%"));
}
predicate.getExpressions().add(cb.notEqual(root.get("id"), 1)); // 管理员除外
}
return predicate;
}
}, pageable);
return pageUser.getContent();
}