一、先整合spring和mybatis:
Junit测试jar(4.12版本)
Mybatis(3.4.5)
Spring相关的jar(spring-context、spring-tx、spring-jdbc、spring-test、spring-aop、 aspectjweaver)
mybatis、spring 整合包(mybatis-spring-x.x.x)
Mysql数据库驱动包
druid数据库连接池包
junit junit 4.12 test org.mybatis mybatis 3.4.5 org.springframework spring-context 5.1.12.RELEASE org.springframework spring-tx 5.1.12.RELEASE org.springframework spring-test 5.1.12.RELEASE org.springframework spring-jdbc 5.1.12.RELEASE org.springframework spring-aop 5.1.12.RELEASE org.aspectj aspectjweaver 1.8.11 org.mybatis mybatis-spring 2.0.3 mysql mysql-connector-java 5.1.35 com.alibaba druid 1.1.10
2、修改 appliactionContext.xml
3、jdbc.properties
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://101.132.167.18:3306/mydatabase
jdbc.username=root
jdbc.password=root
4、引入springmvc及tomcat插件
org.apache.maven.plugins maven-compiler-plugin 3.2 1.8 1.8 UTF-8 org.apache.tomcat.maven tomcat7-maven-plugin 2.2 80 /
5、测试类编写
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath*:application*.xml"})
public class TestMyBatis {@Autowiredprivate AccountService accountService;@Testpublic void test(){System.out.println(accountService);Account accounts = accountService.queryAccount();//for (int i = 0; i < accounts.size(); i++) {System.out.println(accounts);//}}
}
上一篇:如何为博客做seo?