用户登录后读出其发表的文章

本文介绍了一个简单的Java Web应用程序中文章管理模块的设计与实现,包括数据库表结构定义、JSP页面展示及后端DAO层的数据查询逻辑。
create table tb_article(
id int(6) not null auto_increment,
typeId int(3) not null default 8,
title varchar(30) not null default '#',
content text,
phTime timestamp,
number int(6),
primary key(id)
)default charset=utf8;
insert into tb_article(typeId,title,content,number) values(6,'喊赛票奴','好娃,上天那,蓝月呀',100);

head_main.jsp

</head>
<jsp:useBean id="articleDao" scope="request"
	class="com.wy.dao.ArticleDao"></jsp:useBean>
<%
	Integer typeId = null;
	List articleList = articleDao.queryArticle(typeId);
	int articleNumber = articleList.size();
	if (articleNumber > 5) {
		articleNumber = 5;
	}
%>
<body>
	<%
		out.println("come");
	%>
</body>
</html>


ArticleDao.java

public List queryArticle(Integer typeId) {
		List list = new ArrayList();
		String sql = null;
		if (typeId == null)
			sql = "select * from tb_article";
		else
			sql = "select * from tb_article where typeID='" + typeId
					+ "' order by id desc";
		ResultSet rs = connection.executeQuery(sql);
		try {
			while (rs.next()) {
				articleForm = new ArticleForm();
				articleForm.setId(rs.getInt(1));
				System.out.println(rs.getInt(1));
				articleForm.setTypeId(rs.getInt(2));
				System.out.println(rs.getInt(2));
				articleForm.setTitle(rs.getString(3));
				System.out.println(rs.getString(3));
				articleForm.setContent(rs.getString(4));
				System.out.println(rs.getString(4));
				articleForm.setPhTime(rs.getString(5));
				System.out.println(rs.getString(5));
				articleForm.setNumber(rs.getInt(6));
				System.out.println(rs.getInt(6));
				list.add(articleForm);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

运行到这里,已经涉及到2个表了!但是这两个表之间没什么联系,文章并非登录用户所发表。


源代码:http://pan.baidu.com/share/link?shareid=2401642393&uk=3878681452


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值