<pre name="code" class="java"> @Override
public String getElementByIds(String[] elementId) {
String hql = "from ElementProperty where ElementUUid in (:ElementUUid) order by ElementUUid ";
List<ElementProperty> dataProperty = (List<ElementProperty>) getCurrentSession().createQuery(hql).setParameterList("ElementUUid", elementId)
.list();
if(dataProperty == null || dataProperty.size()==0){
return "" ;
}
另外一个例子
@Override
public List<String> findDeviceTokenList(List<Long> userIdList) throws Exception {
if (userIdList == null || userIdList.isEmpty()) {
return new ArrayList<String>(0);
}
String sql = "SELECT device_token FROM users u WHERE u.id IN (:userIdList)";
return session().createSQLQuery(sql).setParameterList("userIdList", userIdList).list();
}

本文介绍两种使用Java进行批量查询数据库的方法。一种是通过UUID查询多个元素属性并按UUID排序;另一种是根据用户ID列表获取对应的设备令牌列表。
278





