【问题标题】:How to fetch users data by date from date to date in spring boot java code如何在spring boot java代码中按日期获取用户数据
【发布时间】:2020-06-25 04:44:24
【问题描述】:

实际上,我怀疑我有很多其他参数的用户列表现在我想根据从日期到日期(每月)过滤数据,有人可以帮我解决这个问题。

【问题讨论】:

    标签: javascript java reactjs spring-boot azure-active-directory


    【解决方案1】:

    您可以使用 Java Streams 过滤数据。

    userList.stream().filter(user -> {
      if(user.getDate() >= fromDate && user.getDate() <=toDate){
        return true;
      }
      return false;
    });
    

    【讨论】:

    • dhruv 裁缝我使用令牌从 azure aad 获取用户数据,现在我正在尝试使用 from 和 to 日期以过滤方式获取用户数据。这样当用户点击 api 时它会给我 json从现在到现在
    【解决方案2】:

    实体

    @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);
            }
        }
    }
    

    【讨论】:

    • Zishan 我使用令牌从 azure aad 获取用户数据,现在我正在尝试使用 from 和 to 日期以过滤的方式获取用户数据。这样当用户点击 api 时,它会给我 json从现在到现在
    猜你喜欢
    • 2021-08-30
    • 2022-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-10
    • 1970-01-01
    相关资源
    最近更新 更多