SQL查询多个字段
query.getResultList() 返回List类型,每个对象类型是Obejct类型的数组。List<Object[]>
import java.math.BigDecimal;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
public class JpaDemoTest {
@PersistenceContext
private EntityManager em;
public void testJpaNativeQuery() {
BigDecimal classNo = null;
BigDecimal studentNo = null;
String remark = null;
String sql = "select t.class_no ,t.student_no ,t.remark from t_student t where t.class_no =:class_no ";
Query query = em.createNativeQuery(sql);
query.setParameter("class_no", 20);
//返回Object[] 类型的List
List objecArraytList = query.getResultList();
for (int i = 0; i < objecArraytList.size(); i++) {
//每个结果是Obect