记录本例查询初衷:

有表:

表1,表2,表3

关系

1 many-to-one 2
2 many-to-one 3

 结果:要通过表3中的条件反向查询表1中相关的数据

 

    
    public Page<WeiCommentComment> findPageWeiCommentCommentByUserid(
            String userid, PageParam pageParam) {
        DetachedCriteria dc = super.getDetachedCriteria(); 
        if(StringUtils.isNotBlank(userid)){
            DetachedCriteria dcwei = dc.createAlias("weiComment", "w");
            dcwei.add(Restrictions.eq("user.idStr", userid));
        }
        Page<WeiCommentComment> page =  super.findPage(dc, pageParam);
        return page;
    }

 

上面介绍:

WeiCommentComment:表1
weiComment:为表1中的定义的关联关系
    @ManyToOne(targetEntity = WeiComment.class)
    @JoinColumn(name="wei_id",updatable=false)
    private WeiComment weiComment;

 

user:为表2中也就是WeiComment 中的表关联关系
    @ManyToOne(targetEntity = NsanbanUser.class)
    @JoinColumn(name="userID",updatable=true)
    private NsanbanUser user;

 

 

如上介绍查询

 

相关文章:

  • 2022-12-23
  • 2021-09-05
  • 2021-09-05
  • 2021-11-30
  • 2021-04-16
  • 2021-09-05
  • 2021-08-07
  • 2021-11-20
猜你喜欢
  • 2021-12-30
  • 2021-11-30
  • 2021-11-30
  • 2021-11-30
  • 2021-08-14
相关资源
相似解决方案