在上一篇文章提到了这个方法,在这里再详细谈谈我对这个方法的理解

使用该方法最直接的好处就是可以根据查询的字段名来获取相应的值

</pre><p>如下是一个查询多字段时的处理情况:</p><p></p><pre name="code" class="java">String sql = "SELECT message_id,app_id FROM message";
        Query query = getSession().createSQLQuery(sql);
        List<Object[]> result = query.list();//默认查询出来的list里存放的是一个Object数组 
        for (Object[] objects : result) {
			String message_id = objects[0].toString();
			String app_id = objects[1].toString();
			System.out.println(message_id+","+app_id);
		}

这里使用了Object[ ],这是默认滴,在取值过程中要遍历,比较麻烦


下面我们使用setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP)方法

String sql = "SELECT message_id,app_id FROM message";
        Query query = getSession().createSQLQuery(sql);
        query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); // 这样子返回Map
        List result = query.list();
        for (Object object : result) {
			Map obj = (Map) object;
			String message_id = obj.get("message_id").toString();
			String app_id = obj.get("app_id").toString();
			System.out.println(message_id+","+app_id);
		}
这里返回Map,就可以直接根据key取相应的值了,更灵活


GitHub 加速计划 / tra / transformers
130.24 K
25.88 K
下载
huggingface/transformers: 是一个基于 Python 的自然语言处理库,它使用了 PostgreSQL 数据库存储数据。适合用于自然语言处理任务的开发和实现,特别是对于需要使用 Python 和 PostgreSQL 数据库的场景。特点是自然语言处理库、Python、PostgreSQL 数据库。
最近提交(Master分支:2 个月前 )
33868a05 * [i18n-HI] Translated accelerate page to Hindi * Update docs/source/hi/accelerate.md Co-authored-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com> * Update docs/source/hi/accelerate.md Co-authored-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com> * Update docs/source/hi/accelerate.md Co-authored-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com> * Update docs/source/hi/accelerate.md Co-authored-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com> --------- Co-authored-by: Kay <kay@Kays-MacBook-Pro.local> Co-authored-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com> 12 天前
e2ac16b2 * rework converter * Update modular_model_converter.py * Update modular_model_converter.py * Update modular_model_converter.py * Update modular_model_converter.py * cleaning * cleaning * finalize imports * imports * Update modular_model_converter.py * Better renaming to avoid visiting same file multiple times * start converting files * style * address most comments * style * remove unused stuff in get_needed_imports * style * move class dependency functions outside class * Move main functions outside class * style * Update modular_model_converter.py * rename func * add augmented dependencies * Update modular_model_converter.py * Add types_to_file_type + tweak annotation handling * Allow assignment dependency mapping + fix regex * style + update modular examples * fix modular_roberta example (wrong redefinition of __init__) * slightly correct order in which dependencies will appear * style * review comments * Performance + better handling of dependencies when they are imported * style * Add advanced new classes capabilities * style * add forgotten check * Update modeling_llava_next_video.py * Add prority list ordering in check_conversion as well * Update check_modular_conversion.py * Update configuration_gemma.py 13 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐