在Hibernate中选择具有两个以上值的查询

时间:2017-04-10 13:16:14

标签: java hibernate spring-mvc

如何编写Hibernate查询以选择具有两个以上值的值?

metrics = new long[]{1, 2, 3};
rprtAutoCustomColum = reportSettingServive.getColumnsMap("1,2,3");

有三个columnId&#39。我想选择columnId和变量名称并存储在HashMap

public Map<Long, String> customeCol = new HashMap<>();

public HashMap<Long, String> getColumnsMap(String columnIds) {
    Session session = null;
    Transaction transaction = null;
    List<ReportsAutomationCustomColumns> automationCustomColumns = new ArrayList();

    SQLQuery query;
    try {
        session = sessionFactory.openSession();
        transaction = (Transaction) session.beginTransaction();
        String hql = "from lxr_reportsauto_customcolumns  where column_id=:columnIds";
        Query query = session.createQuery(hql);
        List<ReportsAutomationCustomColumns> list = query.list();
        transaction.commit();

        list.stream().forEach((ReportsAutomationCustomColumns clist) -> {
            customeCol.put(clist.getColumnId(), clist.getVariableName());
        });
        return (HashMap<Long, String>) customeCol;
    }
}

普通SQL看起来像:

select column_id,variable_name from lxr_reportsauto_customcolumns
where column_id in(1,2,3) order by column_id 

但我希望在Hibernate。

1 个答案:

答案 0 :(得分:1)

您需要使用所需的值创建- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath]; if (indexPath.row == [imageArray count]) { cell.ImageImg.image =[UIImage imageNamed:@"plus.jpg"]; cell.DeleteBtn.hidden=true; [cell.ImageImg.layer setBorderColor: [[UIColor clearColor] CGColor]]; [cell.ImageImg.layer setBorderWidth: 0.5]; } else { cell.DeleteBtn.hidden=false; cell.ImageImg.image=[imageArray objectAtIndex:indexPath.row]; [cell.ImageImg.layer setBorderColor: [[UIColor blackColor] CGColor]]; [cell.ImageImg.layer setBorderWidth: 0.7]; [cell.DeleteBtn addTarget:self action:@selector(RemovePrssd:) forControlEvents:UIControlEventTouchUpInside]; } return cell; } -(void)RemovePrssd:(id)sender{ UIView *senderButton = (UIView*) sender; NSIndexPath *indexPath = [_ImageCollectionVIew indexPathForCell: (UICollectionViewCell *)[[senderButton superview]superview]]; [imageArray removeObjectAtIndex:indexPath.row]; [_ImageCollectionVIew deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]]; } -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == [imageArray count]) { value=@"0"; [_videoController.view removeFromSuperview ]; UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.allowsEditing = YES; picker.sourceType = UIImagePickerControllerSourceTypeCamera; [self presentViewController:picker animated:YES completion:NULL]; } } ,然后将其传递给您的查询,如下所示:

List