Many JSP beginners in learning simple JSP programming, often stay in the JSP inside the SQL statement to tune a JavaBean database connection stage, stalled.
This simple tutorial is expected to help beginners learn to use OOP ideas for JSP programming.
Scenario: A simple news system that consists of 2-3 data tables.
The database system uses MySQL, and of course it is similar to others.
First datasheet, and the main data sheet: News
create table news2 (newsid int not null,
userid int,
kwid int, // 关键词外键
title varchar(100),
content text,
hits int,
cdate varchar2(30),
mdate varchar2(30),
primary key(newsid));
Insert one more sample data:
insert into news2 (newsid, title, content) values (1, 'test title', 'test body');
Design idea: Programming with MVC pattern, packing data in a helper class News.java,
And through the Newsdao.java database operation.
In the design phase, UML is used to sketch the object of the system.
... omitted here
The main methods of Newsdao are:
1. Public News getnewsbyprimarykey (int newsid);
2. Public news[] Getrecentnews ();
3. Public news[] Gethotnews ();
......