Struts 2.1.6 精简实例系列教程(3):新闻管理Model层的开发(整合iBatis)
2009-09-23 00:00:00 来源:WEB开发网写一个Junit测试类来测试一下吧,代码如下:
package cn.simple.manager;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import org.junit.Test;
import cn.simple.pojo.Article;
public class ArticleManagerTest {
@Test
public void testSelectAllArticles() throws SQLException {
List<Article> list = ArticleManager.selectAllArticles();
for(Article a : list){
System.out.println(a.getTitle() + a.getAuthor() + a.getContent() + a.getPubtime());
}
}
@Test
public void testInsertArticle() throws SQLException {
for(int i=0; i<10; i++){
Article article = new Article();
article.setTitle("title-" + i);
article.setAuthor("author-" + i);
article.setContent("content-" + i);
article.setPubtime(new Date());
ArticleManager.insertArticle(article);
}
}
@Test
public void testUpdateArticle() throws SQLException {
Article article = new Article();
article.setId(3);
article.setTitle("title-title");
article.setAuthor("author-author");
ArticleManager.updateArticle(article);
}
@Test
public void testDeleteArticle() throws SQLException {
ArticleManager.deleteArticle(5);
}
}
到此,我们的项目文件列表截图如下:
新闻管理的Model层开发完毕,可以供我们的Action调用了,好,Struts 2.1.6 精简实例系列教程,敬请大家期待下文!
更多精彩
赞助商链接