在mybatis中传递数据库名称

问题描述 投票:0回答:3

我需要通过哈希图中的参数传递数据库名称。

我的Mybatis XML是

<select id="getById" parameterType="hashmap" resultMap="result">
    SELECT * FROM #{db}.CONTACT WHERE CONTACT_NAME = #{name}
</select>

我的Java电话是

hm.put("db","abc");
hm.put("name","def");
Contact c=contactDAO.selectById(hm);

但是出现以下错误

The error occurred while setting parameters
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your      
SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax    
to   use near ''abc'.CONTACT WHERE CONTACT_NAME = 'def'' at line 1

我们不能在mybatis中将数据库名称作为参数传递吗?

java mysql database mybatis ibatis
3个回答
3
投票

您需要使用${}而不是#{}来直接替换String


0
投票

终于成功了。我所做的更改是


0
投票

正如@yalpertem所说(我还不能添加评论):

© www.soinside.com 2019 - 2024. All rights reserved.