Spring JPA实现动态SQL查询,并无实体映射,返回map

/**
     * input about.
     */
    public List getInputResultBySql(String sql) {
        Query query = entityManager.createNativeQuery(sql);
        query.unwrap(NativeQueryImpl.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
        List resultList = query.getResultList();
        //遍历resultList
        for (Map map : resultList) {
            //遍历map
            for (Object key : map.keySet()) {
                //输出key和value
                System.out.println("key=" + key + " value=" + map.get(key));
            }
        }



        return null;
    }

你可能感兴趣的:(spring,sql,服务器)