一列 多列 查询 基于hibernate

package com.haha.test;

import java.util.List;

import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.Session;

import com.haha.dao.HibernateSessionFactory;

public class Test一列 {


public static void main(String[] args) {
String hql="select b.title from Books b where b.title like 'java%'";
Session ss=HibernateSessionFactory.getSession();
Query qq=ss.createQuery(hql);
List<String> list=qq.list();
for(String s:list){
System.out.println(s);
}
}

}

2

package com.haha.test;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.haha.dao.HibernateSessionFactory;

public class Test多列 {

/**
* @param args
*/
public static void main(String[] args) {
String hql=
"select b.title,b.unitprice from Books b where b.title like 'java%'";
Session ss=HibernateSessionFactory.getSession();
Query qq=ss.createQuery(hql);
List<Object[]> list=qq.list();
for(Object[] objs:list){
String title=(String) objs[0];
Double price=(Double) objs[1];
System.out.println(title+","+price);
}

}

}

原文地址:https://www.cnblogs.com/tian114527375/p/4959784.html