Spring与Dao-Jdbc模板-使用Spring的JUnit4测试
2017-04-12 15:43
369 查看
Spring与Dao-Jdbc模板-使用Spring的JUnit4测试
环境搭建参考:http://blog.csdn.net/leisure_life/article/details/70143114
注意:使用Spring的JUnit4测试需要在搭建好的环境中再添加两个jar,
环境搭建参考:http://blog.csdn.net/leisure_life/article/details/70143114
注意:使用Spring的JUnit4测试需要在搭建好的环境中再添加两个jar,
spring-aop-4.2.1.RELEASE.jar和
spring-test-4.2.1.RELEASE.jar
package com.hk.springdao.test; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.hk.springdao.beans.Student; import com.hk.springdao.service.IStudentService; /** * * @author 浪丶荡 * */ @RunWith(SpringJUnit4ClassRunner.class)//运行环境 @ContextConfiguration(locations="classpath:applicationContext.xml") public class MyTest_spring { @Autowired private IStudentService studentService; @Test public void testAdd(){ Student stu = new Student("浪丶荡",18); studentService.addStudent(stu ); } @Test public void testRemove(){ studentService.removeStudent(2); } @Test public void testModify(){ Student stu = new Student(); stu.setId(3); stu.setAge(10); stu.setName("黑旋风"); studentService.modifyStudent(stu); } }
相关文章推荐
- 黑马程序员 JDBC_使用模板方法设计模式处理DAO中的方法(李勇老师)
- Spring dao框架——jdbc模板批量操作
- spring使用JdbcTemplate和jdbcDaosupport及具名参数使用
- spring: 使用Spring提供的JDBC模板(使用profiles选择数据源/使用基于JDBC驱动的数据源)
- 详细解读Spring2.5 +Struts1.3 框架(使用Spring声明式事物管理和springjjdbc模板)
- Spring 使用原生的jdbc或整合ORM操作数据库的模板编程
- Spring_23-24使用 JdbcTemplate和JdbcDaoSupport和NamedParameterJdbcTemplate
- Spring_使用 JdbcTemplate和JdbcDaoSupport
- Spring -- spring 中使用jdbc, c3p0连接池, dao概念
- 使用spring的jdbcTemplate-----用JDBC模板查询数据库
- 【Spring实战】—— 15 Spring JDBC模板使用
- Spring与Dao-Jdbc模板实现增删改查
- 使用Spring对JDBC的Dao的支持类操作数据库
- Spring -- spring 中使用jdbc, c3p0连接池, dao概念
- Spring使用JdbcTemplate、JdbcDaoSupport和返回表自增主键值
- [Java 8 & Spring JDBC] 使用Spring JDBC和Lambda表达式简化DAO
- Spring_Spring与DAO_Spring的Jdbc模板
- Spring中使用Jdbcdaosupport、C3P0和properties
- [原创]java WEB学习笔记109:Spring学习---spring对JDBC的支持:使用 JdbcTemplate 查询数据库,简化 JDBC 模板查询,在 JDBC 模板中使用具名参数两种实现
- 【Spring实战】—— 15 Spring JDBC模板使用