在不使用hibernate的情况下,使用它来操作数据库也不错,至少不用自己去封装了。java里的东西就是多。。。
在applicationContext.xml中的配置
- <beanid="jdbcTemplate"
- class="org.springframework.jdbc.core.JdbcTemplate">
- <propertyname="dataSource">
- <refbean="dataSource"/>
- </property>
- </bean>
在DAO层的使用
- publicListgetBranchById(StringbranchId){
- Stringsql="select*fromdeptwheredeptid='"+branchId+"'";
- try{
- returnjdbcTemplate.queryForList(sql);
- }catch(DataAccessExceptione){
- throwe;
- }
- }