使用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>
本文介绍如何在Spring框架中通过JdbcTemplate统一管理SQL语句,利用properties文件存储命名SQL,实现代码的清晰性和可维护性提升。
1323

被折叠的 条评论
为什么被折叠?



