Examples of global variable mybatise

Foreword

Sometimes you need to configure the daily work in the configuration file global variables, because these things will not change, and each mapper will pass the Senate, then also seemed a bit cumbersome, but fortunately mybatis itself is supported by a global variable, today, the work used, and record it.

mybatis can set a global variable, the database can be used for the type of label, such as: dbType=oracle ,dbType=mysql;

ConfigurationProperties by parameter setting, setting is as follows:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="configLocation" value="classpath:mybatis/mybatis-config.xml"/> <property name="configurationProperties"> <props> <prop key="dbType">oracle</prop> </props> </property> </bean>

java obtain this parameter can be:

sqlSessionFactory.getConfiguration().getVariables().getProperty("dbType")

to sum up

That's all for this article, I hope the contents of this paper, we study or work can bring some help, if in doubt you can leave a message exchange, thank you for the support scripts House.

Guess you like

Origin www.cnblogs.com/Hackerman/p/11703365.html