发表于: 2017-08-05 02:34:59

2 1047


今天对昨天的代码进行了一些修改,然后编写了不规范的测试类来测试一下基本功能。

补项目结构图:(那些jar有些不知道有没有用就都加进来了。。)

一、代码修改:

1.修改StudentDAO接口中的updateStu函数,将返回值由Student修改为boolean,参数列表增加long id。

public abstract boolean updateStu(Student stu, long id);

2.据1中接口的修改,修改StudentDAOImpl中的updateStu函数:(从Eclipse编辑器复制粘贴过来似乎还是没格式。。)

同时也加上非空判断。

3.修改addStu函数,去掉id的手动插入,增加name、major、jnshuId的非空判断:

3.查询函数的修改

将各查询函数中的RowMapper抽取成一个类,

将所有sql语句修改为查询全部属性;将RowMapper的匿名内部类改为匿名对象,例如:


二、测试代码

还不太清楚Junit单元测试和src/test/java这个文件夹的用法,就还是在main/java中写了个简单的功能测试代码,来测试数据操作类:

一堆bug修改中。。。。

bug1:url错误。

错误原因:①数据库名是students,少了个s;

 ②是正斜杠而不是反斜杠

bug2:Access denied for user 'asus'@'localhost' (using password: YES)

错误原因:似乎是applicationContext.xml文件中的格式写错了

将${username}改为root后,暂时没这个问题了,明天看看如何正确读取db.properties中的数据,再做修改。

bug3:Table 'students.student' doesn't exist

错误原因:各sql语句中插入的表名是student,应该为students

bug4:Column 'jnshuId' not found.

错误原因:mapRow中的rs.getString("")引号中应为数据库的列名,而不是Student类中的属性名。

bug5:打印结果为数组地址

修改:将showStu函数中的sop(obj)改为foreach循环遍历。

修改后,可以正确查询数据库了:

但仍存在警告:

Sat Aug 05 03:10:00 CST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

这个警告不知道是什么意思,明天查查看。


明天先测试完各个功能。然后学习下Junit,编写正规的测试单元。


返回列表 返回列表
评论

    分享到