Q题目
现在要求,模拟一个类似的功能,实体为一个网上书店,要求显示最近的三条浏览记录,使用数据库存储数据和查询数据,如下图
例如:
1)现有如下网上书店:
本站书籍目录:
JAVA
C++
C语言
Linux
Android
最近三次浏览记录:
3)浏览第一个商品后,若为Java,显示界面
本站书籍目录:
JAVA
C++
C语言
Linux
Android
最近三次浏览记录:
JAVA
4)浏览第二个商品,若为C++
5)浏览第三个商品,若为Java,此时涉及一个排序问题了,最前的必须是最近浏览的。
6)浏览第四个商品,为C语言
具体分析见:http://blog.csdn.net/baidu_37107022/article/details/72783206
实现代码
目录
注意:数据库驱动jar包,以及配置文件info.properties
数据库数据如下:
book类
package com.tcb.domain;
public class Book {
private int id;
private String name;
private int price;
private String author;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public Book(String name, int price, String author) {
super();
this.name = name;
this.price = price;
this.author = author;
}
@Override
public String toString() {
return "Book [id=" + id + ", name=" + name + ", price=" + price + ", author=" + author + "]";
}
public Book() {
super();
// TODO Auto-generated constructor stub
}
}
bookDao类:查询数据库内容
package com.tcb.dao;
import java.sql.Connection