SpringSide4中多对多如何用SearchFilter查询
< 返回列表时间: 2016-05-30来源:开源中国
HDC调试需求开发(15万预算),能者速来!>>>
有两个表book图书表和cat分类表 还有一个中间表book_cat(book_id,cat_id)

//book实体类 private Set<BookCat> cats;//所属分类 @ManyToMany(cascade = CascadeType.PERSIST) @JoinTable(name = "book_cat", joinColumns = @JoinColumn(name = "book_id"), inverseJoinColumns = @JoinColumn(name = "cat_id")) public Set<BookCat> getCats() { return cats; } public void setCats(Set<BookCat> cats) { this.cats = cats; }



//cat实体类 private Set<Book> books; @ManyToMany(cascade = CascadeType.PERSIST) @JoinTable(name = "book_cat_relation", joinColumns = @JoinColumn(name = "cat_id"), inverseJoinColumns = @JoinColumn(name = "book_id")) public Set<Book> getBooks() { return books; } public void setBooks(Set<Book> books) { this.books = books; }



字段是set集合类型的 我需要通过cat_id查询到book表的内容 请问怎样用SearchFilter实现查询set集合字段


怎样利用下面的方法查询 /** * 创建动态查询条件组合 * * @param userId * @param searchParams * @return */ private Specification<Book> buildSpecification( Map<String, Object> searchParams) { Map<String, SearchFilter> filters = SearchFilter.parse(searchParams); //filters.put("id", new SearchFilter("id", Operator.EQ, catId)); Specification<Book> spec = DynamicSpecifications.bySearchFilter( filters.values(), Book.class); return spec; }
谢谢大家(特地注册个号进来问 ,没想到还要等1个小时..... ,希望大家帮帮忙呀 实现过类似功能的朋友给点经验 )





热门排行