【发布时间】:2020-06-25 04:44:24
【问题描述】:
实际上,我怀疑我有很多其他参数的用户列表现在我想根据从日期到日期(每月)过滤数据,有人可以帮我解决这个问题。
【问题讨论】:
标签: javascript java reactjs spring-boot azure-active-directory
实际上,我怀疑我有很多其他参数的用户列表现在我想根据从日期到日期(每月)过滤数据,有人可以帮我解决这个问题。
【问题讨论】:
标签: javascript java reactjs spring-boot azure-active-directory
您可以使用 Java Streams 过滤数据。
userList.stream().filter(user -> {
if(user.getDate() >= fromDate && user.getDate() <=toDate){
return true;
}
return false;
});
【讨论】:
实体
@Entity
public class User {
@Id
Long id;
@CreationTimestamp
Date date;
}
存储库
public interface UserRepository extends JpaRepository<User, Long> {
List<User> findAllByOrderByDate();
}
服务
@Service
public class UserService{
@Autowired
UserRepository userRepository;
List<User> users = userRepository.findAllByOrderByDate();
List<User> userList= new ArrayList<>();
for(User user: users){
if(user.getDate >= fromDate && user.getDate() <=toDate ){
userList.add(user);
}
}
}
【讨论】: