1、查询指定字段
public List<Object[]> getUseList( Integer index, Integer offset, String state, String search ){ String sqlSelect = "select user_id, user_name "; String sql = sqlSelect + " from users where user_status in (:state) limit :index, :offset"; SQLQuery sqlQuery = sessionFactory.getCurrentSession().createSQLQuery(sql); sqlQuery.setInteger("index", index); sqlQuery.setInteger("offset", offset); String [] stateList = state.split(","); sqlQuery.setParameterList("state", stateList); search = "%" + search + "%"; sqlQuery.setString("userName", search); List<Object[]> restList = sqlQuery.list(); return restList; }
获取结果集
for(Object[] restArr : restList){ Map<String, Object> userMap = new HashMap<>(); Integer userId = (Integer) restArr[0]; String userName = (String) restArr[1]; }