userid int,
kwid int, // 关键词外键
title varchar(100),
content text,
hits int,
cdate varchar2(30),
mdate varchar2(30),
primary key(newsid));
再插入一个样本数据:
insert into news2 (newsid, title, content) values (1, 'test title', 'test body');
设计思路:用mvc模式编程,将数据以一个helper class News.java 打包,并通过NewsDAO.java进行数据库操作。设计阶段,用UML勾画出系统的object.
...此处省略
NewsDAO的主要方法有:
1. public News getNewsByPrimaryKey(int newsid);
2. public News[] getRecentNews();
3. public News[] getHotNews();
......
News.java的代码如下:
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/webkaifa/)package news;
public class News {
private int newsid;
private int userid;
private int kwid;
private int hits;
private String title;
private String content;
private String cdate;
private String mdate;
public News(){ }
public News(int newsid,int userid,int kwid,int hits,String title,String content,String cdate)
{
this.newsid=newsid;
this.userid=userid;
this.kwid=kwid;
this.hits=hits;
this.title=title;
this.content=content;
this.cdate=cdate;
}
public News(int id, String t, String cnt) {
this.newsid = id;
this.title = t;
this.content = cnt;
}
public int getNewsid()
{
return newsid;
}
public void setNewsid(int newsid)
{
this.newsid=newsid;
}
public int getUserid()
{
return userid;
}
public void setUserid(int userid)
{
this.userid=userid;
}
public int getKwid()
{
return kwid;
}
public void setKwid(int kwid)
{
this.kwid=kwid;
}
public int getHits()
{
return hits;
}
public void setHits(int hits)
{
this.hits=hits;
}
public String getTitle()
{
return title;
}
public void setTitle(String title)
{
this.title=title;
}
public String getContent()
{
return content;
}
public void setContent(String content)
{
this.content=content;
}
public String getCdate()
{
return cdate;
}
public void setCdate(String cdate)
{
this.cdate=cdate;
}
}
说明:这个程序可以用作javabean,作为录入表单的参数携带者(params Holder).