使用spring的JdbcTemplate时,为了统一管理sql语句,可以采用如下方式:
1、新建properties文件,将命名sql写在里边。如account.properties
addAccount = INSERT INTO table(f1,f2)
VALUES (\#loginName\#,\#password\#)
2、spring文件中加载该properties
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:/sql/account.properties</value>
</list>
</property>
</bean>
新建bean。如AccountSql,有属性addAccount,添加getter/setter
<bean id="accountSql" class="xxxx.AccountSQL" scope="singleton">
<property name="addAccount" value="${addAccount}"/>
</bean>