English 中文(简体)
从地图绘制商获取财产
原标题:Accessing properties from Mappers

I have a linked server in SQL Server so when I query something, it has to be something like this:

SELECT * FROM [SERVERNAME].[DBNAME].[SCHEMA].[TABLE]

现在,我必须采用这一方式,向现有项目查询<编码>servername 、dbnamesschema<>/code>,载于我的代码<>application.properties

是否有办法从我的Maper(xml)获取这些财产?

问题回答

You can use properties.
With MyBatis-Spring-Boot, you can define properties in your application.properties with the prefix mybatis.configuration.variables. [1].

mybatis.configuration.variables.db_servername=YOUR_SERVER_NAME
mybatis.configuration.variables.db_dbname=YOUR_DB_NAME
mybatis.configuration.variables.db_schema=YOUR_SCHEMA

也可参考同一份<代码>应用.properties所确定的变量。

mybatis.configuration.variables.db_servername=${servername}
mybatis.configuration.variables.db_dbname=${dbname}
mybatis.configuration.variables.db_schema=${schema}

然后,你可以使用<代码>{}在地图上使用这些变量。

SELECT * FROM [${db_servername}].[${db_dbname}].[${db_schema}].[TABLE]

注:<代码>#{} 赢得t work。 See this FAQ/2005/ for the differences。

*** 准则指出,序号为mybatis.configuration-properties.,但我刚刚测试了该编号,并且做了一些工作。 然而,这可能是我的错误。 我计划在我有一定时间时进行调查。





相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签