Query query = session .createQuery("select count(*) from Privilege p where p.name like ?"); query.setString(0, "%" + name + "%");// 注意这里不能写成setString(0," '%" + name + "%' "; 否则查不出来结果,不能加‘单引号