2

プロジェクトでSpringとMybatisを使用しています。プロジェクトは、SQL Server Oracle などの任意のプラットフォームで実行できます。

私は1つの問題に直面していますプロパティファイル、アプリケーションコンテキストファイルからMybatis Mapperファイルへの変数値にアクセスしたいです。

For.eg : ApplicationContext.xml - Spring ファイル
config.properties ファイル

上記のファイルで、変数をデカルしたい
pName = XYZとしましょう

Mybatis Mapper XMLファイルでこのpNameにアクセスしたいです。

<select id="getValue" parameterType="java.lang.String" >
${pName}
</select>

他の解決策があれば大歓迎です。

4

2 に答える 2

3

スプリングウェイにアクセスするには:

<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=MODULEyourpropertiesfile.propertiesで定義します

于 2015-11-17T12:38:36.823 に答える