以前用QBC我们都用session.createCriteria()来开始查询,不过这种方式已经被废弃 @deprecated (since 5.2) for Session, use the JPA Criteria,很明显作者认为以前创建QBC查询方式不够好,现在改成用 JAP Criteria,通过下面的一个查询简单看下。
@Test
public void testQBCQuery() {
//1. 创建CriteriaBuilder对象
CriteriaBuilder builder = session.getCriteriaBuilder();
//2. 获取 CriteriaQuery
CriteriaQuery criteriaQuery = builder.createQuery(Grade.class);
//3. 构建搜索语句 select * from grade
Root root = criteriaQuery.from(Grade.class);
//3.1 构建条件 + where id > 2
criteriaQuery.where(builder.gt(root.get("id"), 2));
//3.2 构建排列顺序 + order by id desc
criteriaQuery.orderBy(builder.desc(root.get("id")));
//4. 执行查询, 返回结果集
List list = session.createQuery(criteriaQuery).getResultList();
for (Grade student : list) {
System.out.println(student);
}
}
String hql = "select c.name from Contact c";
List list = session.createQuery(hql).getResultList();
for (Object object : list) { System.out.println(object); }
7. HQL 查询多列字段,以数组盛装单行查询字段结果集,然后将各行的结果集放进List数组里
String hql = "select c.name, c.birthday from Contact c";
List list = session.createQuery(hql).getResultList();
for (Object[] objects : list) { System.out.println(Arrays.toString(objects)); }
8. HQL 查询多列字段,以对象盛装单行查询字段结果集,然后将各行的结果集放进List数组里
String hql = "select new Contact(c.name, c.birthday) from Contact c";
List list = session.createQuery(hql).getResultList();
for (Object object : list) { System.out.println(object); }
注意:要求实体类必须有对应的构造方法
9. HQL 查询结果排序
String hql = "from Contact where id>? order by id desc";
List list = session.createQuery(hql).setParameter(0, 2).getResultList();
System.out.println(list);
按照查询结果 id 进行降序排序
10. HQL 分页查询
String hql = "from Contact";
List list = session.createQuery(hql)
.setFirstResult(1)
.setMaxResults(2)
.getResultList();
System.out.println(list);
--只包含执行部分的PL/SQL块
--set serveroutput off
begin
dbms_output.put_line('Hello,everyone!');
end;
select * from emp;
--包含定义部分和执行部分的PL/SQL块
declare
v_ename varchar2(5);
begin
select
转:http://stackoverflow.com/questions/6352208/how-to-solve-plugin-execution-not-covered-by-lifecycle-configuration-for-sprin
maven报错:
Plugin execution not covered by lifecycle configuration:
要使用MonkeyRunner,就要学习使用Python,哎
先抄一段官方doc里的代码
作用是启动一个程序(应该是启动程序默认的Activity),然后按MENU键,并截屏
# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRun