思维导图 – Servlet+ThreadLocal分包管理实例
一:本文思维导图
二:ThreadLocal原理图
三:代码:
实体层entity Book.java
package entity;
public class Book {
/*私有属性*/
private int id;
private String name;
private String author;
private String publisher;
private int price;
/*默认构造函数*/
public Book() {
super();
}
public Book(String name, String author, String publisher, int price) {
super();
this.name = name;
this.author = author;
this.publisher = publisher;
this.price = price;
}
public Book(int id, String name, String author, String publisher, int price) {
super();
this.id = id;
this.name = name;
this.author = author;
this.publisher = publisher;
this.price = price;
}
/*对象属性操作*/
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 String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getPublisher() {
return publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
}
数据访问层data access object(dao)—BaseDao.java
package dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class BaseDao {
// 数据库驱动
private static final String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
// 连接数据库的url路径
private static final String url = "jdbc:sqlserver://localhost:1433;DatabaseName=MyDB";
// 用户名
private s