Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在spring boot中获取所有保存的帖子?_Spring_Spring Boot_Hibernate - Fatal编程技术网

如何在spring boot中获取所有保存的帖子?

如何在spring boot中获取所有保存的帖子?,spring,spring-boot,hibernate,Spring,Spring Boot,Hibernate,我必须像用户和食物这样的实体。用户可以保存食物帖子。我正在尝试获取所有保存的用户帖子,但我如何才能做到这一点?我正在食品库中编写hibernate查询,但无法访问保存的食品帖子。 这是我的密码: @Data @Entity public class User extends BaseEntity { @Column(unique = true, nullable = false) private String username; @JsonIgnore @On

我必须像用户和食物这样的实体。用户可以保存食物帖子。我正在尝试获取所有保存的用户帖子,但我如何才能做到这一点?我正在食品库中编写hibernate查询,但无法访问保存的食品帖子。 这是我的密码:

@Data
@Entity
public class User extends BaseEntity {

    @Column(unique = true, nullable = false)
    private String username;

    @JsonIgnore
    @OneToMany
    private List<Food> savedRecipes;
}
@数据
@实体
公共类用户扩展BaseEntity{
@列(unique=true,nullable=false)
私有字符串用户名;
@杰索尼奥雷
@独身癖
私有列表保存目录;
}
食物类别:

@Data
@Entity
@Where(clause = "deleted = false")
public class Food extends BaseEntity {

    private String foodName;
    private String recipe;
  
    @OneToMany
    private List<Category> categoryList;

 
    @ManyToOne(fetch = FetchType.EAGER)
    @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
    @JoinColumn(name = "user_id", referencedColumnName = "id")
    private User user;

}
@数据
@实体
@其中(子句=“已删除=错误”)
公共级食品安全实体{
私有字符串foodName;
私有字符串配方;
@独身癖
私有列表分类列表;
@manytone(fetch=FetchType.EAGER)
@JsonIgnoreProperties({“HibernateLazInitializer”,“handler”})
@JoinColumn(name=“user\u id”,referencedColumnName=“id”)
私人用户;
}
存储库代码:

@Repository
public interface FoodRepository extends JpaRepository<Food,Long> {

    List<Food> findAllByFoodNameContaining(String searchedValue);

    List<Food> findAllByCategoryListInAndDeletedFalse(List<Category> categoryList);

    List<Food> findAllByUserId(Long id);

    List<Food> findAllByUserSavedRecipes(Long id);

}
@存储库
公共接口FoodRepository扩展了JpaRepository{
列出findAllByFoodNameContaining(字符串搜索值);
列出FindAllByCategoryList和DeletedFalse(列表类别列表);
列表findallbyserid(长id);
列出findAllByUserSavedRecipes(长id);
}
试试这种方法。
列出findallbyser(用户)

通过调用下面的方法,您可以轻松获取用户保存的所有食物

第一个:
List result=User.getSavedRecipes()


第二:
List result=FoodRepository.findAllByUserId(长id)

非常感谢