---
title: "IBatis中如何获取sqlId和传入参数对应的缓存Key值"
author: "chenjc_it"
date: "2012-01-10T09:23:26Z"
tags: []
categories: ["企业架构"]
slug: "ibatis-sqlid-key"
draft: false
lastmod: "2012-01-10T09:23:26Z"
id: 1339715
url: "https://chenjc-it.iteye.com/blog/1339715"
---

有时候我们想自己实现IBatis的缓存机制，在DAO添加缓存的方法给开发人员使用，可以通过以下的代码获取对应的Key值：

 

```
SqlMapClientImpl sci = (SqlMapClientImpl)this.sqlMapClient;
MappedStatement ms = sci.getMappedStatement(sqlId);
		
SessionScope sessionScope = new SessionScope();     
sessionScope.incrementRequestStackDepth();     
StatementScope statementScope = new StatementScope(sessionScope);     
ms.initRequest(statementScope);    
CacheKey key = ms.getCacheKey(statementScope, params);
```