我在项目中使用Spring和Mybatis。项目可以在任何平台上运行,例如SQL Server Oracle等。
我面临1问题,我想访问变量值,从属性文件,应用程序上下文文件到Mybatis Mapper文件。
For.eg:ApplicationContext.xml-弹簧文件
config.properties文件
在上面的文件中,要贴花的变量让我们说
pName = XYZ
我想在Mybatis Mapper XML文件中访问此pName。
<select id="getValue" parameterType="java.lang.String" >
${pName}
</select>
如果有其他解决方案最受欢迎,那怎么可能?
访问弹簧方式:使用
<util:properties id="myPropertyConfigurer" location="classpath:yourpropertiesfile.properties"/>
<context:property-placeholder properties-ref="myPropertyConfigurer" order="1" ignore-unresolvable="true" />
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="applicationDataSource" />
<property name="configLocation" value="classpath:sqlMapConfig.xml" />
<property name="configurationProperties" ref="myPropertyConfigurer"></property>
</bean>
在您的映射器xml文件中:
<select id="searchSomeOne" parameterType="map" .....>
SELECT
${pName} AS module
FROM MY_TABLE
WHERE
COL_ONE = #{moduleName} and
COL_TWO like #{username}
</select>
并pName=MODULE
在yourpropertiesfile.properties中定义
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句