---
title: "hql动态绑定参数"
author: "jveqi"
date: "2012-10-22T14:28:11Z"
tags: []
categories: ["编程语言"]
slug: "hql"
draft: false
lastmod: "2012-10-22T14:28:11Z"
id: 1702990
url: "https://balzac.iteye.com/blog/1702990"
---

01. **private** Query setParameter(Query query, Map&lt;String, Object&gt; map) {
02. **if** (map != **null**) {
03. Set&lt;String&gt; keySet = map.keySet();
04. **for** (String string : keySet) {
05. Object obj = map.get(string);
06. //这里考虑传入的参数是什么类型，不同类型使用的方法不同
07. **if**(obj **instanceof** Collection&lt;?&gt;){
08. query.setParameterList(string, (Collection&lt;?&gt;)obj);
09. }**else** **if**(obj **instanceof** Object\[]){
10. query.setParameterList(string, (Object\[])obj);
11. }**else**{
12. query.setParameter(string, obj);
13. }
14. }
15. }
16. **return** query;
17. }