通过Spring配置数据源及单元测试2010-03-04 12:441.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:DFDB"></property>
<property name="username" value="scott"></property>
<property name="password" value="tiger"></property>
</bean>
<bean id="abstractDao" abstract="true">
<property name="dataSource">
<ref local="dataSource"/>
</property>
</bean>
<bean id="catDao" class="org.catpro.dao.impl.CatDaoImpl" parent="abstractDao">
</bean>
</beans>
2,Dao
package org.catpro.dao;
import java.util.List;
import org.catpro.vo.Cat;
public interface CatDao {
List<Cat> searchCat();
int delete(String kinds);
}
3,DaoImpl
package org.catpro.dao.impl;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import org.catpro.dao.CatDao;
import org.catpro.dao.conn.ConnectionPool;
import org.catpro.vo.Cat;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
public class CatDaoImpl extends JdbcDaoSupport implements CatDao {
private JdbcTemplate jdbcTemplate;
/**
* Dao 根据种类删除信息
*/
public int delete(String kinds) {
int result = 0;
String sql = "delete from cat where kinds=?";
Object[] parameValues=new Object[]{kinds};
int[] types=new int[]{Types.VARCHAR};
this.jdbcTemplate=this.getJdbcTemplate();
result=this.jdbcTemplate.update(sql,parameValues,types);
return result;
}
}
4,单元测试
package org.catpro.dao.test;
import org.catpro.dao.CatDao;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import junit.framework.TestCase;
public class CatDaoTest extends TestCase {
private ApplicationContext context = null;
@Override
protected void setUp() throws Exception {
super.setUp();
context=new ClassPathXmlApplicationContext("org/catpro/dao/config/dao-config.xml");
}
public void testDelete(){
CatDao catDao=(CatDao)context.getBean("catDao");
int result=catDao.delete("中国");
assertTrue(result>0);
}
}
分享到:
相关推荐
赠送jar包:jakarta.xml.bind-api-2.3.3.jar; 赠送原API文档:jakarta.xml.bind-api-2.3.3-javadoc.jar; 赠送源代码:jakarta.xml.bind-api-2.3.3-sources.jar; 赠送Maven依赖信息文件:jakarta.xml.bind-api-...
赠送jar包:spring-data-keyvalue-2.3.9.RELEASE.jar; 赠送原API文档:spring-data-keyvalue-2.3.9.RELEASE-javadoc.jar; 赠送源代码:spring-data-keyvalue-2.3.9.RELEASE-sources.jar; 赠送Maven依赖信息文件:...
赠送jar包:spring-boot-configuration-processor-2.3.12.RELEASE.jar; 赠送原API文档:spring-boot-configuration-processor-2.3.12.RELEASE-javadoc.jar; 赠送源代码:spring-boot-configuration-processor-...
赠送jar包:spring-security-core-5.3.9.RELEASE.jar; 赠送原API文档:spring-security-core-5.3.9.RELEASE-javadoc.jar; 赠送源代码:spring-security-core-5.3.9.RELEASE-sources.jar; 赠送Maven依赖信息文件:...
赠送jar包:spring-beans-5.0.10.RELEASE.jar; 赠送原API文档:spring-beans-5.0.10.RELEASE-javadoc.jar; 赠送源代码:spring-beans-5.0.10.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-beans-5.0.10....
赠送jar包:springfox-spring-webflux-3.0.0.jar; 赠送原API文档:springfox-spring-webflux-3.0.0-javadoc.jar; 赠送源代码:springfox-spring-webflux-3.0.0-sources.jar; 赠送Maven依赖信息文件:springfox-...
config.properties:数据库配置文件 log4j.properties:mybatis日志文件 spring-mvc.xml:spring-MVC配置文件 spring-mybatis.xml:mybatis的配置文件 spring.xml
赠送jar包:springfox-spring-web-2.9.2.jar; 赠送原API文档:springfox-spring-web-2.9.2-javadoc.jar; 赠送源代码:springfox-spring-web-2.9.2-sources.jar; 赠送Maven依赖信息文件:springfox-spring-web-...
这是一个springmvc-config.xml文件,<?xml version="1.0" encoding="UTF-8"?> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:...
赠送jar包:spring-webmvc-5.0.8.RELEASE.jar; 赠送原API文档:spring-webmvc-5.0.8.RELEASE-javadoc.jar; 赠送源代码:spring-webmvc-5.0.8.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-webmvc-5.0.8....
赠送jar包:spring-plugin-metadata-2.0.0.RELEASE.jar; 赠送原API文档:spring-plugin-metadata-2.0.0.RELEASE-javadoc.jar; 赠送源代码:spring-plugin-metadata-2.0.0.RELEASE-sources.jar; 赠送Maven依赖信息...
赠送jar包:spring-context-support-1.0.10.jar; 赠送原API文档:spring-context-support-1.0.10-javadoc.jar; 赠送源代码:spring-context-support-1.0.10-sources.jar; 赠送Maven依赖信息文件:spring-context-...
赠送jar包:spring-security-rsa-1.0.10.RELEASE.jar; 赠送原API文档:spring-security-rsa-1.0.10.RELEASE-javadoc.jar; 赠送源代码:spring-security-rsa-1.0.10.RELEASE-sources.jar; 赠送Maven依赖信息文件:...
赠送jar包:spring-security-config-5.0.7.RELEASE.jar; 赠送原API文档:spring-security-config-5.0.7.RELEASE-javadoc.jar; 赠送源代码:spring-security-config-5.0.7.RELEASE-sources.jar; 赠送Maven依赖信息...
赠送jar包:jasypt-spring-boot-3.0.4.jar; 赠送原API文档:jasypt-spring-boot-3.0.4-javadoc.jar; 赠送源代码:jasypt-spring-boot-3.0.4-sources.jar; 赠送Maven依赖信息文件:jasypt-spring-boot-3.0.4.pom;...
spring cloud的pom文件,解决maven无法导入依赖的问题,spring-cloud-dependencies-Finchley.SR2.pom文件
赠送jar包:spring-boot-actuator-2.3.12.RELEASE.jar; 赠送原API文档:spring-boot-actuator-2.3.12.RELEASE-javadoc.jar; 赠送源代码:spring-boot-actuator-2.3.12.RELEASE-sources.jar; 赠送Maven依赖信息...
赠送jar包:spring-session-data-redis-2.0.4.RELEASE.jar; 赠送原API文档:spring-session-data-redis-2.0.4.RELEASE-javadoc.jar; 赠送源代码:spring-session-data-redis-2.0.4.RELEASE-sources.jar; 赠送...
赠送jar包:spring-boot-actuator-autoconfigure-2.2.0.RELEASE.jar; 赠送原API文档:spring-boot-actuator-autoconfigure-2.2.0.RELEASE-javadoc.jar; 赠送源代码:spring-boot-actuator-autoconfigure-2.2.0....
赠送jar包:spring-boot-actuator-autoconfigure-2.2.0.RELEASE.jar; 赠送原API文档:spring-boot-actuator-autoconfigure-2.2.0.RELEASE-javadoc.jar; 赠送源代码:spring-boot-actuator-autoconfigure-2.2.0....