发表于: 2017-12-27 23:07:07
2 540
今天完成的事情
1.写了一个比较正格的单元测试并跑了一遍
package test.com.spring;
import com.spring.Student;
import com.spring.StudentJDBCTemplate;
import com.spring.StudentMapper;
import org.junit.Test;
import org.junit.Before;
import org.junit.After;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import javax.sql.DataSource;
import java.util.List;
public class StudentJDBCTemplateTest {
@Before
public void before() throws Exception {
}
@After
public void after() throws Exception {
}
ApplicationContext context =
new ClassPathXmlApplicationContext("Beans.xml");
StudentJDBCTemplate studentJDBCTemplate =
(StudentJDBCTemplate)context.getBean("studentJDBCTemplate");
@Test
public void testSetDataSource() throws Exception {
//TODO: Test goes here...
}
@Test
public void testCreate() throws Exception {
studentJDBCTemplate.create("xiaojj", 999);
}
@Test
public void testGetStudent() throws Exception {
Student student = studentJDBCTemplate.getStudent(20);
System.out.print("ID : " + student.getId() );
System.out.print(", Name : " + student.getName() );
System.out.println(", Age : " + student.getAge());
}
@Test
public void testListStudents() throws Exception {
List<Student> students = studentJDBCTemplate.listStudents();
for (Student record : students) {
System.out.print("ID : " + record.getId());
System.out.print(", Name : " + record.getName());
System.out.println(", Age : " + record.getAge());
}
}
@Test
public void testDelete() throws Exception {
studentJDBCTemplate.delete(21);
}
@Test
public void testUpdate() throws Exception {
studentJDBCTemplate.update(21, 50);
}
}
下面是运行的结果:
结果有点儿太多了,放不开了
2.给我的mybatis demo开了log4j
这是log4j的properties配置文件
上面这个是结果
3.深度思考
(1)maven是项目管理工具,是多人开发统一代码风格和规范的工具,为日后项目合并,发布等等提供便利,无兼容性问题;
Ant是一个构建java项目的工具;
maven是Ant的扩展产物,较Ant有如下优点:
内置依赖管理<dependency>;内置软件构建的生命周期:default、clean、site;隐形规则可以更简单构建文件:/src/main、test/java等;pom.xml项目管理(Project Object Model)。
(2)clean代表清理target文件,即上次构建项目时生成的文件;install安装依赖至本地资源库,将不是maven建的artifacts安装至本地资源库;package是打包命令,暂时还未使用过;install将jar包安装到本地库、package将jar包打到本项目的target下;deploy命令是发布,在整合或者发布环境下执行,将最终版本的包拷贝到远程repository(仓库),实现共享。
(3)maven跳过单元测试:在pom.xml文件中添加
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
(4)用日志代替System.out.println的好处就是:在有大量打印信息时,可以通过关闭日志打印阻止控制台打印,便捷。除此之外还能便于计算进程效率,输出线程信息等等。
(5)用Long替换Date类型就是因为,Date类型有特定模式,不仅插入数据不友好,而且也不安全。DATE、DATETIME将显示服务器的本地时间,而不是你的服务器。如果需要知道你自己的当地时间,那么需要根据时区来手动修改,有些麻烦。大多数应用程序不关心绝对时间是多少。 当前时间通常用于计算自某个事件以来经过了多少时间,整数类型方便计算时间差。
(6)不存在连续性,合并表的时候会出现重复。使用分布式数据库以及数据合并的情况下时不能使用自增ID的。
今天遇到的问题
就是单元测试啦,我在写单元测试的时候突然不知道该怎么写了,就那种突然一片空白的感觉,很确定是因为自己单元测试进行的屈指可数,太不熟练导致的;所以废了一些时间才把这个问题解决。
第二个问题就是插入两亿条数据,这个sql生成也好慢啊...师兄们都是怎么弄的这一步呢?(求解!大师兄!)
今天的收获
查漏查到了一个junit单元测试,以为自己会了,结果写不出来;最后整出来了,顺便给mybatis开了log4j
明天计划的事情
明天继续深度思考剩余的问题,然后继续查漏补缺,顺便学习一下将代码上传至svn或者git
麻烦师兄审核!
评论