用戶模塊 要登陸後才能購買,因此我們先寫購買模塊. 設計實體 設計資料庫表 編寫DAO 測試DAO 抽取DAO 編寫Service 前臺樣式 head.jsp head.css 效果: 實現登陸註冊功能 當點擊登陸按鈕的時候,把數據帶過去給Servlet,讓Servlet調用BusinessServ ...
用戶模塊
要登陸後才能購買,因此我們先寫購買模塊.
設計實體
private String id;
private String username;
private String password;
private String email;
private String cellphone;
private String address;
//各種setter、getter
設計資料庫表
CREATE TABLE user (
id VARCHAR(40) PRIMARY KEY,
username VARCHAR(20) NOT NULL,
cellphone VARCHAR(20) NOT NULL,
address VARCHAR(40) NOT NULL,
email VARCHAR(30),
password VARCHAR(30) NOT NULL
);
編寫DAO
/**
* 用戶的登錄註冊模塊
* 1:登陸
* 2:註冊
* 3:根據id查找具體的用戶
*/
public class UserDaoImpl {
public void register(User user) {
QueryRunner queryRunner = new QueryRunner(Utils2DB.getDataSource());
String sql = "INSERT INTO user (id,username,cellphone,address,email,password) VALUES(?,?,?,?,?,?)";
try {
queryRunner.update(sql, new Object[]{user.getId(),user.getUsername(), user.getCellphone(), user.getAddress(), user.getEmail(), user.getPassword()});
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public User login(String username, String password) {
QueryRunner queryRunner = new QueryRunner(Utils2DB.getDataSource());
String sql = "SELECT * FROM user WHERE username = ? AND password=?";
try {
return (User) queryRunner.query(sql, new Object[]{username, password}, new BeanHandler(User.class));
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public User find(String id) {
QueryRunner queryRunner = new QueryRunner(Utils2DB.getDataSource());
String sql = "SELECT * FROM user WHERE id=?";
try {
return (User) queryRunner.query(sql, id, new BeanHandler(User.class));
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
測試DAO
public class UserDemo {
UserDaoImpl userDao = new UserDaoImpl();
@Test
public void add() {
User user = new User();
user.setId("1");
user.setUsername("zhong");
user.setPassword("123");
user.setCellphone("10085");
user.setAddress("廣州蘿崗");
user.setEmail("[email protected]");
userDao.register(user);
}
@Test
public void find() {
String id = "1";
User user = userDao.find(id);
System.out.println(user.getEmail());
}
@Test
public void login() {
String username = "zhong";
String password = "123";
User user = userDao.login(username, password);
System.out.println(user.getAddress());
}
}
抽取DAO
public interface UserDao {
void register(User user);
User login(String username, String password);
User find(String id);
}
編寫Service
private UserDao userDao = DaoFactory.getInstance().createDao("zhongfucheng.dao.impl.UserDaoImpl", UserDao.class);
public void registerUser(User user) {
userDao.register(user);
}
public User loginUser(String username,String password) {
return userDao.login(username, password);
}
public User findUser(String id) {
return userDao.find(id);
}
前臺樣式
- head.jsp
<div id="User">
用戶名:<input type="text" name="username">
密碼:<input type="password" name="password">
<button name="login">登陸</button>
<button name="register">註冊</button>
</div>
- head.css
#body {
position: relative;
}
#user {
position: absolute;
margin-top: 130px;
margin-left: 1364px;
}
- 效果:
實現登陸註冊功能
當點擊登陸按鈕的時候,把數據帶過去給Servlet,讓Servlet調用BusinessService方法,實現登陸。註冊同理.....因此,我們需要用到JavaScript代碼
- head.jsp
<c:if test="${user==null}" >
<div id="User">
用戶名:<input type="text" id="username">
密碼:<input type="password" id="password">
<button name="login" onclick="login()">登陸</button>
<button name="register" onclick="register()">註冊</button>
</div>
</c:if>
<c:if test="${user!=null}" >
<div id="User">
歡迎您:${user.username} <a href="${pageContext.request.contextPath}/UserServlet?method=Logout">註銷</a>
</div>
</c:if>
- javaScript代碼
<script type="text/javascript">
function login() {
//得到輸入框的數據
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
//跳轉到相對應的Servlet上
window.location.href = "${pageContext.request.contextPath}/UserServlet?method=login&username=" + username + "&password=" + password;
}
function register() {
//跳轉到註冊頁面
window.location.href = "${pageContext.request.contextPath}/client/register.jsp";
}
</script>
- UserServlet
String method = request.getParameter("method");
BussinessServiceImpl service = new BussinessServiceImpl();
if (method.equals("login")) {
try {
//得到頁面傳遞過來的數據
String username = request.getParameter("username");
String password = request.getParameter("password");
User user = service.loginUser(username, password);
request.getSession().setAttribute("user",user);
request.getRequestDispatcher("/client/head.jsp").forward(request, response);
} catch (Exception e) {
request.setAttribute("message", "登陸失敗了!");
request.getRequestDispatcher("/message.jsp").forward(request, response);
}
} else if (method.equals("register")) {
try {
//得到JSP傳遞過來的數據,封裝成Bean對象
User user = WebUtils.request2Bean(request, User.class);
user.setId(WebUtils.makeId());
service.registerUser(user);
request.setAttribute("message", "註冊成功了!");
} catch (Exception e) {
e.printStackTrace();
request.setAttribute("message", "註冊失敗了!");
}
request.getRequestDispatcher("/message.jsp").forward(request, response);
} else if (method.equals("Logout")) {
//銷毀session
request.getSession().invalidate();
//回到首頁
request.getRequestDispatcher("/client/head.jsp").forward(request, response);
}
購買模塊
在顯示圖書的時候,順便添加購買的超鏈接
<li><a href="#">購買</a></li>
設計購物車實體
如果不清楚為什麼這樣設計,可參考我之前的博文:http://blog.csdn.net/hon_3y/article/details/56481439#t5
- Cart實體
public class Cart {
private Map<String, CartItem> map = new HashMap<>();
private double price;
//提供把商品添加到購物的功能
public void addBook2Cart(Book book) {
//得到對應的購物項
CartItem cartItem = map.get(book.getId());
//如果是null,說明購物車還沒有該購物項
if (cartItem == null) {
cartItem = new CartItem();
cartItem.setQuantity(1);
cartItem.setBook(book);
cartItem.setPrice(book.getPrice());
//把購物項加到購物車中
map.put(book.getId(), cartItem);
} else {
//如果購物車有該購物項了,那麼將購物項的數量+1
cartItem.setQuantity(cartItem.getQuantity() + 1);
}
}
//購物車的價錢是購物項價錢的總和
public double getPrice() {
double totalPrice = 0;
for (Map.Entry<String, CartItem> me : map.entrySet()) {
CartItem cartItem = me.getValue();
totalPrice += cartItem.getPrice();
}
return totalPrice;
}
public Map<String, CartItem> getMap() {
return map;
}
public void setMap(Map<String, CartItem> map) {
this.map = map;
}
public void setPrice(double price) {
this.price = price;
}
}
設計購物項實體
public class CartItem {
private Book book;
private double price;
private int quantity;
public double getPrice() {
return this.book.getPrice() * this.quantity;
}
public void setPrice(double price) {
this.price = price;
}
public Book getBook() {
return book;
}
public void setBook(Book book) {
this.book = book;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
}
處理用戶想要買的書籍Servlet
<li><a href="${pageContext.request
.contextPath}/BuyServlet?book_id=${book.id}">購買</a></li>
- BuyServlet
BussinessServiceImpl service = new BussinessServiceImpl();
//先檢查該用戶是否登陸了。
User user = (User) request.getSession().getAttribute("user");
if (user == null) {
request.setAttribute("message", "您還沒登陸,請登陸了再來購買");
request.getRequestDispatcher("/message.jsp").forward(request, response);
return ;
}
//如果登陸了...
//得到該用戶的購物車
Cart cart = (Cart) request.getSession().getAttribute("cart");
if (cart == null) {
cart = new Cart();
request.getSession().setAttribute("cart", cart);
}
//得到用戶想買的書籍
String book_id = request.getParameter("book_id");
Book book = service.findBook(book_id);
//把書籍添加到購物車中
service.buyBook(cart, book);
request.setAttribute("message", "該商品已添加到購物車中");
request.getRequestDispatcher("/message.jsp").forward(request,response);
提供顯示購物車商品的Servlet
//先判斷該用戶是否登陸了
User user = (User) request.getSession().getAttribute("user");
if (user == null) {
request.setAttribute("message", "您還沒有登陸呢!");
request.getRequestDispatcher("/message.jsp").forward(request, response);
return;
}
//如果登陸了.....
Cart cart = (Cart) request.getSession().getAttribute("cart");
//把該用戶的購物車給JSP頁面顯示
request.setAttribute("cart", cart);
request.getRequestDispatcher("/client/listCart.jsp").forward(request, response);
顯示購物車的JSP頁面
<c:if test="${empty(cart.map)}">
您還沒有購買過任何商品哦!!!
</c:if>
<table border="1px">
<c:if test="${!empty(cart.map)}">
<h1>您購物車下有如下的商品:</h1><br>
<tr>
<td>書名:</td>
<td>作者:</td>
<td>數量:</td>
<td>價錢:</td>
</tr>
<c:forEach items="${cart.map}" var="cartItme">
<tr>
<td>${cartItme.value.book.name}</td>
<td>${cartItme.value.book.author}</td>
<td>${cartItme.value.quantity}</td>
<td>${cartItme.value.price}</td>
</tr>
</c:forEach>
</c:if>
</table>
效果:
訂單模塊
在前臺用戶界面中,當用戶要把購物車付款時,應該提供生成訂單的超鏈接....
設計訂單實體
訂單應該包含id,收貨人信息,下單的時間,訂單的總價,訂單的狀態【有無發貨】..而不應該包含商品的信息的。商品的信息用一個專門的”訂單項“來表示
一個訂單對應多個訂單項,這是一對多的關係!
private String id;
//下單的時間、日期、狀態
private Date date;
private double price;
private boolean state;
//一個用戶可以有多個訂單,把用戶記住
private String user_id;
//一個訂單中有多個訂單項
private Set<OrderItem> items = new HashSet<>();
//各種的setter和getter
設計訂單項實體
private String id;
//一本書對應多個訂單項,訂單項一定是由書組成,記住書
private String book_id;
private double price;
private int quantity;
//各種的setter和getter
設計資料庫表
- 訂單表
mysql不能創建名為”order”的表,後邊加個s就可以
CREATE TABLE orders (
id VARCHAR(40) PRIMARY KEY,
date DATE NOT NULL,
user_id VARCHAR(40) NOT NULL,
state BOOLEAN,
price DOUBLE,
CONSTRAINT user_id_FK FOREIGN KEY (user_id) REFERENCES user (id)
);
- 訂單項表:
CREATE TABLE orderItem (
id VARCHAR(40) PRIMARY KEY,
price DOUBLE,
quantity INT,
order_id VARCHAR(40) ,
book_id VARCHAR(40) ,
CONSTRAINT order_id_FK FOREIGN KEY (order_id) REFERENCES orders (id),
CONSTRAINT book_id_FK FOREIGN KEY (book_id) REFERENCES book (id)
);
- 表之間的結構:
設計Dao
public class OrderDaoImpl implements zhongfucheng.dao.OrderDao {
@Override
public void addOrder(Order order) {
QueryRunner queryRunner = new QueryRunner(Utils2DB.getDataSource());
String sql1 = "INSERT INTO orders(id,ordertime,user_id,state,price) VALUES(?,?,?,?,?)";
try {
//訂單的基本信息
queryRunner.update(sql1, new Object[]{order.getId(), order.getOrdertime(), order.getUser_id(), order.isState(), order.getPrice()});
//訂單項的信息
String sql2 = "INSERT INTO orderItem(id,price,quantity,order_id,book_id) VALUES(?,?,?,?,?)";
Set<OrderItem> items = order.getItems();
for (OrderItem item : items) {
queryRunner.update(sql2, new Object[]{item.getId(), item.getPrice(), item.getQuantity(), item.getOrder_id(), item.getBook_id()});
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
@Override
public Order findOrder(String id) {
QueryRunner queryRunner = new QueryRunner(Utils2DB.getDataSource());
Order order;
try {
//找出訂單的基本信息
String sql = "SELECT * FROM orders WHERE id=?";
order = (Order) queryRunner.query(sql, new BeanHandler(Order.class), new Object[]{id});
//找出訂單的所有訂單項
String sql2 = "SELECT * FROM orderItem WHERE order_id=?";
List<OrderItem> list = (List<OrderItem>) queryRunner.query(sql2, new BeanListHandler(OrderItem.class), new Object[]{order.getId()});
System.out.println("這是資料庫拿到的list集合:"+list.size());
//將所有訂單項裝到訂單裡邊
order.getItems().addAll(list);
System.out.println("這是資料庫拿到的"+order.getItems().size());
//找出該訂單是屬於哪一個用戶的
String sql3 = "SELECT * FROM orders o,user u WHERE o.user_id=u.id AND o.id=? ";
User user = (User) queryRunner.query(sql3, new BeanHandler(User.class), new Object[]{order.getId()});
order.setUser_id(user.getId());
return order;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
//更新訂單的狀態
public void updateState(String id) {
QueryRunner queryRunner = new QueryRunner(Utils2DB.getDataSource());
String sql = "UPDATE orders SET state=? WHERE id=?";
try {
queryRunner.update(sql, new Object[]{true, id});
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
//查看已經發貨或沒發貨的訂單信息
public List<Order> getAllOrder(boolean state) {
QueryRunner queryRunner = new QueryRunner(Utils2DB.getDataSource());
String sql = "SELECT * FROM orders WHERE state=? ";
try {
return (List<Order>) queryRunner.query(sql, new BeanListHandler(Order.class), new Object[]{state});
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
//通過用戶的id查找用戶的訂單,可能不止一個
public List<Order> findUserOrder(String user_id) {
QueryRunner queryRunner = new QueryRunner(Utils2DB.getDataSource());
String sql = "SELECT * FROM orders WHERE user_id=? ";
try {
return List<Order> queryRunner.query(sql, new BeanHandler(Order.class), new Object[]{user_id});
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
二次更新
在編寫dao的時候,尤其是Add方法。它是將所有數據都封裝到Order對象上,然後取出數據,把數據插入到數據表中
- 其實,我們的Order和OrderItem的操作可以分開。OrderItem也可以另外編寫一個Dao,那麼我們在插入完Order對象之後,得到Order對象返回的主鍵,再調用OrderItemDao的方法來插入OrderItem的數據,這樣我覺得會讓代碼清晰一些。
- 在OrderItemDao中接收的是一個List
抽取成DAO介面
public interface OrderDao {
void addOrder(Order order);
Order findOrder(String id);
List<Order> getAllOrder(boolean state);
void updateState(String user_id);
List<Order> findUserOrder(String user_id);
}
BussinessService
private OrderDao orderDao = DaoFactory.getInstance().createDao("zhongfucheng.dao.impl.OrderDaoImpl", OrderDao.class);
public void createOrder(Cart cart, User user) {
//訂單的基本信息
String order_id = WebUtils.makeId();
Order order = new Order();
order.setId(order_id);
order.setPrice(cart.getPrice());
order.setOrdertime(new Date());
order.setState(false);
order.setUser_id(user.getId());
//訂單項的基本信息
//得到每個購物項,購物項就作為訂單項
for (Map.Entry<String, CartItem> me : cart.getMap().entrySet()) {
OrderItem orderItem = new OrderItem();
CartItem cartItem = me.getValue();
orderItem.setId(WebUtils.makeId());
orderItem.setPrice(cartItem.getPrice());
orderItem.setBook_id(cartItem.getBook().getId());
orderItem.setQuantity(cartItem.getQuantity());
orderItem.setOrder_id(order_id);
order.getItems().add(orderItem);
}
orderDao.addOrder(order);
}
public Order findOrder(String user_id) {
return orderDao.findOrder(user_id);
}
public List<Order> getAllOrder(boolean state) {
return orderDao.getAllOrder(state);
}
public void sendOutOrder(String id) {
orderDao.updateState(id);
}
public List<Order> findUserOrder(String user_id) {
return orderDao.findUserOrder(user_id);
}
生成訂單的Servlet
BussinessServiceImpl service = new BussinessServiceImpl();
//檢查該用戶的購物車是否有商品
Cart cart = (Cart) request.getSession().getAttribute("cart");
if (cart == null) {
request.setAttribute("message", "您購物車沒有商品,無法生成訂單");
request.getRequestDispatcher("/message.jsp").forward(request, response);
return;
}
//如果有商品,得到當前用戶
User user = (User) request.getSession().getAttribute("user");
service.createOrder(cart, user);
request.setAttribute("message", "訂單已經生成了,準備好錢來收貨把");
request.getRequestDispatcher("/message.jsp").forward(request, response);
return;
用戶查詢自己的訂單Servlet
<a href="${pageContext.request.contextPath}/LookOrder" target="body">查看訂單</a>
BussinessServiceImpl service = new BussinessServiceImpl();
//檢查該用戶是否登陸了
User user = (User) request.getSession().getAttribute("user");
if (user == null) {
request.setAttribute("message", "您還沒登陸,等您登陸了再來看把");
request.getRequestDispatcher("/message.jsp").forward(request, response);
return;
}
//用戶登陸了!
Order order = service.findUserOrder(user.getId());
//交給相對應的JSP 顯示
request.setAttribute("order", order);
request.setAttribute("user",user);
request.getRequestDispatcher("/client/listOrder.jsp").forward(request, response);
return ;
顯示訂單數據的JSP
<c:if test="${order==null}">
您還沒有下過任何訂單!!
</c:if>
<c:if test="${order!=null}">
<table border="1px">
<tr>
<td>下單人:</td>
<td>訂單時間</td>
<td>訂單狀態</td>
<td>訂單價錢</td>
</tr>
<tr>
<td>${user.username}</td>
<td>${order.ordertime}</td>
<td>${order.state==false?"未發貨":"已發貨"}</td>
<td>${order.price}</td>
</tr>
</table>
</c:if>
效果:
後臺查詢訂單的狀況Servlet
<a href="${pageContext.request.contextPath}/OrderServlet?state=false" target="body">待處理訂單</a><br>
<a href="${pageContext.request.contextPath}/OrderServlet?state=true" target="body">已發貨訂單</a><br>
BussinessServiceImpl service = new BussinessServiceImpl();
String state = request.getParameter("state");
if (state.equals("true")) {
List<Order> list = service.getAllOrder(true);
request.setAttribute("list",list);
} else if (state.equals("false")) {
List<Order> list = service.getAllOrder(false);
request.setAttribute("list", list);
}
request.getRequestDispatcher("/background/listOrder.jsp").forward(request, response);
顯示訂單狀況的JSP
<c:if test="${empty(list)}">
還沒有任何訂單哦!
</c:if>
<c:if test="${!empty(list)}">
<table border="1px">
<tr>
<td>下單人:</td>
<td>訂單時間</td>
<td>訂單狀態</td>
<td>訂單價錢</td>
<td>操作</td>
</tr>
<c:forEach items="${list}" var="order">
<tr>
<td>${order.user_id}</td>
<td>${order.ordertime}</td>
<td>${order.state==false?"未發貨":"已發貨"}</td>
<td>${order.price}</td>
<td>
<a href="${pageContext.request.contextPath}/orderItemServlet?order_id=${order.id}">查看詳細信息</a>
<a href="#">刪除</a>
</td>
</tr>
</c:forEach>
</table>
</c:if>
查看具體訂單的詳細信息Servlet
BussinessServiceImpl service = new BussinessServiceImpl();
//得到用戶想要查看詳細信息的表單
String order_id = request.getParameter("order_id");
Order order = service.findOrder(order_id);
//將該order對象給相對應的JSP顯示
request.setAttribute("order", order);
request.getRequestDispatcher("/background/listDetail.jsp").forward(request, response);
查看具體訂單的詳細信息JSP
<table border="1px">
<tr>
<td>書籍的編號</td>
<td>價錢</td>
<td>數量</td>
<td>操作</td>
</tr>
<c:forEach items="${order.items}" var="item">
<tr>
<td>${item.book_id}</td>
<td>${item.price}</td>
<td>${item.quantity}</td>
<td><a href="${pageContext.request.contextPath}/SendOutServlet?id=${order.id}">發貨</a></td>
</tr>
</c:forEach>
</table>
處理髮貨的Servlet
BussinessServiceImpl service = new BussinessServiceImpl();
String id = request.getParameter("id");
service.sendOutOrder(id);
request.setAttribute("message", "已發貨!");
request.getRequestDispatcher("/message.jsp").forward(request, response);
return;
效果:
添加許可權控制
目前為止,我們已經學習了動態代理技術和註解技術了。於是我們想要為之前的bookStore項目添加許可權控制.....
只有用戶有許可權的時候,後臺管理才可以進行相對應的操作.....
實現思路
之前我們做許可權管理系統的時候,是根據用戶請求的URI來判斷該鏈接是否需要許可權的。這次我們使用動態代理的技術和註解來判斷:用戶調用該方法時,檢查該方法是否需要許可權...
根據MVC模式,我們在web層都是調用service層來實現功能的。那麼我們具體的思路是這樣的:
- web層調用service層的時候,得到的並不是ServiceDao對象,而是我們的代理對象
- 在service層中的方法添加註解,如果方法上有註解,那麼說明調用該方法需要許可權...
- 當web層調用代理對象方法的時候,代理對象會判斷該方法是否需要許可權,再給出相對應的提示....
設計實體、資料庫表
上次我們做的許可權管理系統是引入了角色這個概念的,這次主要為了練習動態代理和註解技術,就以簡單為主,不引入角色這個實體。直接是用戶和許可權之間的關係了。
Privilege實體
public class Privilege {
private String id ;
private String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
資料庫表
- privilege表
CREATE TABLE privilege (
id VARCHAR(40) PRIMARY KEY,
name VARCHAR(40)
);
privilege和user是多對多的關係,於是使用第三方表來維護他們的關係
- user_privilege表
CREATE TABLE user_privilege (
privilege_id VARCHAR(40),
user_id VARCHAR(40),
PRIMARY KEY (privilege_id, user_id),
CONSTRAINT privilege_id_FK FOREIGN KEY (privilege_id) REFERENCES privilege(id),
CONSTRAINT user_id_FK1 FOREIGN KEY (user_id) REFERENCES user(id)
);
添加測試數據
為了方便,直接添加數據了。就不寫詳細的DAO了。
- 在資料庫中添加了兩個許可權
- 為id為1的user添加了兩個許可權
編寫DAO
後面在動態代理中,我們需要檢查該用戶是否有許可權...那麼就必須查找出該用戶擁有的哪些許可權。再看看用戶有沒有相對應的許可權
//查找用戶的所有許可權
public List<Privilege> findUserPrivilege(String user_id) {
QueryRunner queryRunner = new QueryRunner(Utils2DB.getDataSource());
String sql = "SELECT p.* FROM privilege p, user_privilege up WHERE p.id = up.privilege_id AND up.user_id = ?";
try {
return (List<Privilege>) queryRunner.query(sql, new Object[]{user_id}, new BeanListHandler(Privilege.class));
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
抽取到介面上
List<Privilege> findUserPrivilege(String user_id);
註解模塊
- 編寫註解
@Retention(RetentionPolicy.RUNTIME)
public @interface permission {
String value();
}
- 在Service層方法中需要許可權的地方添加註解CategoryServiceImpl
@permission("添加分類")
/*添加分類*/
public void addCategory(Category category) {
categoryDao.addCategory(category);
}
/*查找分類*/
public void findCategory(String id) {
categoryDao.findCategory(id);
}
@permission("查找分類")
/*查看分類*/
public List<Category> getAllCategory() {
return categoryDao.getAllCategory();
}
抽取Service
把Service的方法抽取成ServiceDao。在Servlet中,也是通過ServiceFactory來得到Service的對象【和DaoFactory是類似的】
CategoryService
@permission("添加分類")
/*添加分類*/ void addCategory(Category category);
/*查找分類*/