分類管理模塊
數(shù)據(jù)表結(jié)構(gòu)設(shè)計(jì)
分類表

CREATE TABLE、mmall_ category' (
'id' int(11) NOT NULL AUTO_ INCREMENT COMMENT ' 類別Id',
'parent_ id' int(11) DEFAULT NULL COMMENT '父類 別id當(dāng)id=0時(shí)說明是根節(jié)點(diǎn),一級(jí)類別' ,
'name' varchar(50) DEFAULT NULL COMMENT ' 類別名稱',
'status' tinyint(1) DEFAULT '1' COMMENT ' 類別狀態(tài)1-正常,2-已廢棄',
'sort_order' int(4) DEFAULT NULL COMMENT ' 排序編號(hào),同類展示順序,數(shù)值相等則自然排序' ,
'create_ time' datetime DEFAULT NULL COMMENT '創(chuàng)建時(shí)間',
'update_ time' datetime DEFAULT NULL COMMENT ' 更新時(shí)間' ,
PRIMARY KEY ( id')
) ENGINE=InnoDB AUTO_ INCREMENT=100032 DEFAULT CHARSET=utf8
1.parent_id是因?yàn)榉诸惒捎脴錉罘诸?,遞歸需要邊界條件。
2.父類別id=0時(shí),說明是根節(jié)點(diǎn),一級(jí)類別,此時(shí)為return條件。
3.status可選為1或2,1表示類別正常,2表示該類別已廢棄。
涉及知識(shí)點(diǎn)
如何處理復(fù)雜對(duì)象排重
如何設(shè)計(jì)及封裝無(wú)限層級(jí)的樹狀數(shù)據(jù)結(jié)構(gòu)
通過設(shè)置parent_id及id,id=0時(shí),說明是根節(jié)點(diǎn),一級(jí)類別
- 遞歸算法的設(shè)計(jì)思想
查詢當(dāng)前節(jié)點(diǎn)下面的子節(jié)點(diǎn),以及子節(jié)點(diǎn)的子節(jié)點(diǎn)

equals() 的作用是 用來(lái)判斷兩個(gè)對(duì)象是否相等
//沒有重寫equals()
Person p1 = new Person("eee", 100);
Person p2 = new Person("eee", 100);
System.out.printf("%s\n", p1.equals(p2)); //false
重寫了Person的equals()函數(shù):當(dāng)兩個(gè)Person對(duì)象的 name 和 age 都相等,則返回true。
/**
* @desc Person類。
*/
private static class Person {
int age;
String name;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String toString() {
return name + " - " +age;
}
/**
* @desc 覆蓋equals方法
*/
@Override
public boolean equals(Object obj){
if(obj == null){
return false;
}
//如果是同一個(gè)對(duì)象返回true,反之返回false
if(this == obj){
return true;
}
//判斷是否類型相同
if(this.getClass() != obj.getClass()){
return false;
}
Person person = (Person)obj;
return name.equals(person.name) && age==person.age;
}
}
重寫equal 和hashcode方法
使用==操作符檢查“參數(shù)是否為這個(gè)對(duì)象的引用”;
使用instanceof操作符檢查“參數(shù)是否為正確的類型”;
對(duì)于類中的關(guān)鍵屬性,檢查參數(shù)傳入對(duì)象的屬性是否與之相匹配;
編寫完equals方法后,問自己它是否滿足對(duì)稱性、傳遞性、一致性;
重寫equals時(shí)總是要重寫hashCode;
不要將equals方法參數(shù)中的Object對(duì)象替換為其他的類型,在重寫時(shí)不要忘掉@Override注解。
接口設(shè)計(jì)
1.獲取品類子節(jié)點(diǎn)(平級(jí))
http://localhost:8080/manage/category/get_category.do
http://localhost:8080/manage/category/get_category.do?categoryId=0
http://localhost:8080/manage/category/get_category.do?categoryId=2
/manage/category/get_category.do
request
categoryId(default=0)
response
success
{
"status": 0,
"data": [
{
"id": 2,
"parentId": 1,
"name": "手機(jī)",
"status": true,
"sortOrder": 3,
"createTime": 1479622913000,
"updateTime": 1479622913000
},
{
"id": 4,
"parentId": 1,
"name": "移動(dòng)座機(jī)",
"status": true,
"sortOrder": 5,
"createTime": 1480059936000,
"updateTime": 1480491941000
}
]
}
2.增加節(jié)點(diǎn)
/manage/category/add_category.do
request
parentId(default=0)
categoryName
response
success
{
"status": 0,
"msg": "添加品類成功"
}
3.修改品類名字
http://localhost:8080/manage/category/set_category_name.do?categoryId=999&categoryName=%E5%98%BB%E5%98%BB
http://localhost:8080/manage/category/set_category_name.do?categoryId=1&categoryName=%E5%98%BB%E5%98%BB
/manage/category/set_category_name.do
request
categoryId
categoryName
response
success
{
"status": 0,
"msg": "更新品類名字成功"
}
4.獲取當(dāng)前分類id及遞歸子節(jié)點(diǎn)categoryId
http://localhost:8080/manage/category/get_deep_category.do?categoryId=100001
/manage/category/get_deep_category.do
request
categoryId
response
success
{
"status": 0,
"data": [
100009,
100010,
100001,
100006,
100007,
100008
]
}
商品模塊
數(shù)據(jù)表結(jié)構(gòu)設(shè)計(jì)
產(chǎn)品表

create table mmall_product(
id int(11) primary key auto_increment,
category_id int(11),
sub_images text,
price decimal(20,2),
status int(6) DEFAULT 1
)
1.category_id將來(lái)在表關(guān)系中要采用外鏈。
2.圖片url存放相對(duì)地址,若圖片服務(wù)器遷移或者域名修改,只需要修改前綴即可
3.text格式可以存放的內(nèi)容比varchar更大,存放圖片地址,采用json格式,用于拓展。主圖取圖片地址中的第一張。
4.price采用decimal(20,2)說明價(jià)格整體最多20位(其中有兩位是小數(shù))。后面會(huì)學(xué)習(xí)如何解決丟失精度的問題。
5.status為商品狀態(tài),1-在售,2-下架,3-刪除。
涉及知識(shí)點(diǎn)
FTP服務(wù)的對(duì)接、SpringMVC文件上傳
流讀取Properties配置文件的PropertiesUtil工具類

joda-time快速入門 靜態(tài)塊
Mybatis-PageHelper高校準(zhǔn)確地分頁(yè)及動(dòng)態(tài)排序


Mybatis對(duì)List遍歷的實(shí)現(xiàn)方法
Mybatis對(duì)where語(yǔ)句動(dòng)態(tài)拼裝的幾個(gè)版本演變


POJO、BO、VO 和 POJO、VO

功能
前臺(tái)功能
產(chǎn)品搜索
動(dòng)態(tài)排序列表
商品詳情
后臺(tái)功能
商品列表
商品搜素
圖片上傳
富文本上傳
商品詳情
商品上下架
增加商品
更新商品
接口設(shè)計(jì)
【門戶】
1.產(chǎn)品搜索及動(dòng)態(tài)排序List
/product/list.do
http://localhost:8080/product/list.do?keyword=&categoryId=1&orderBy=price_desc
request
categoryId
keyword
pageNum(default=1)
pageSize(default=10)
orderBy(default=""):排序參數(shù):例如price_desc,price_asc
response
success
{
"status": 0,
"data": {
"pageNum": 1,
"pageSize": 10,
"size": 2,
"orderBy": null,
"startRow": 1,
"endRow": 2,
"total": 2,
"pages": 1,
"list": [
{
"id": 1,
"categoryId": 3,
"name": "iphone7",
"subtitle": "雙十一促銷",
"mainImage": "mainimage.jpg",
"status":1,
"price": 7199.22
},
{
"id": 2,
"categoryId": 2,
"name": "oppo R8",
"subtitle": "oppo促銷進(jìn)行中",
"mainImage": "mainimage.jpg",
"status":1,
"price": 2999.11
}
],
"firstPage": 1,
"prePage": 0,
"nextPage": 0,
"lastPage": 1,
"isFirstPage": true,
"isLastPage": true,
"hasPreviousPage": false,
"hasNextPage": false,
"navigatePages": 8,
"navigatepageNums": [
1
]
}
}
2.產(chǎn)品detail
/product/detail.do
http://localhost:8080/product/detail.do?productId=2
request
productId
response
success
{
"status": 0,
"data": {
"id": 2,
"categoryId": 2,
"name": "oppo R8",
"subtitle": "oppo促銷進(jìn)行中",
"mainImage": "mainimage.jpg",
"subImages": "[\"mmall/aa.jpg\",\"mmall/bb.jpg\",\"mmall/cc.jpg\",\"mmall/dd.jpg\",\"mmall/ee.jpg\"]",
"detail": "richtext",
"price": 2999.11,
"stock": 71,
"status": 1,
"createTime": "2016-11-20 14:21:53",
"updateTime": "2016-11-20 14:21:53"
}
}
【后臺(tái)】
1.產(chǎn)品list
http://localhost:8080/manage/product/list.do
/manage/product/list.do
request
pageNum(default=1)
pageSize(default=10)
response
success
{
"status": 0,
"data": {
"pageNum": 1,
"pageSize": 10,
"size": 2,
"orderBy": null,
"startRow": 1,
"endRow": 2,
"total": 2,
"pages": 1,
"list": [
{
"id": 1,
"categoryId": 3,
"name": "iphone7",
"subtitle": "雙十一促銷",
"mainImage": "mainimage.jpg",
"status":1,
"price": 7199.22
},
{
"id": 2,
"categoryId": 2,
"name": "oppo R8",
"subtitle": "oppo促銷進(jìn)行中",
"mainImage": "mainimage.jpg",
"status":1,
"price": 2999.11
}
],
"firstPage": 1,
"prePage": 0,
"nextPage": 0,
"lastPage": 1,
"isFirstPage": true,
"isLastPage": true,
"hasPreviousPage": false,
"hasNextPage": false,
"navigatePages": 8,
"navigatepageNums": [
1
]
}
}
2.產(chǎn)品搜索
http://localhost:8080/manage/product/search.do?productName=p
http://localhost:8080/manage/product/search.do?productId=1
/manage/product/search.do
request
productName
productId
pageNum(default=1)
pageSize(default=10)
response
success
{
"status": 0,
"data": {
"pageNum": 1,
"pageSize": 10,
"size": 1,
"orderBy": null,
"startRow": 1,
"endRow": 1,
"total": 1,
"pages": 1,
"list": [
{
"id": 1,
"categoryId": 3,
"name": "iphone7",
"subtitle": "雙十一促銷",
"mainImage": "mainimage.jpg",
"price": 7199.22
}
],
"firstPage": 1,
"prePage": 0,
"nextPage": 0,
"lastPage": 1,
"isFirstPage": true,
"isLastPage": true,
"hasPreviousPage": false,
"hasNextPage": false,
"navigatePages": 8,
"navigatepageNums": [
1
]
}
}
3.圖片上傳
/manage/product/upload.do
request
<form name="form2" action="/manage/product/upload.do" method="post" enctype="multipart/form-data">
<input type="file" name="upload_file">
<input type="submit" value="upload"/>
</form>
response
success
{
"status": 0,
"data": {
"uri": "e6604558-c0ff-41b9-b6e1-30787a1e3412.jpg",
"url": "http://img.happymmall.com/e6604558-c0ff-41b9-b6e1-30787a1e3412.jpg"
}
}
4.產(chǎn)品詳情
http://localhost:8080/manage/product/detail.do?productId=2
/manage/product/detail.do
request
productId
response
success
{
"status": 0,
"data": {
"id": 2,
"categoryId": 2,
"parentCategoryId":1,
"name": "oppo R8",
"subtitle": "oppo促銷進(jìn)行中",
"imageHost": "http://img.happymmall.com/",
"mainImage": "mainimage.jpg",
"subImages": "[\"mmall/aa.jpg\",\"mmall/bb.jpg\",\"mmall/cc.jpg\",\"mmall/dd.jpg\",\"mmall/ee.jpg\"]",
"detail": "richtext",
"price": 2999.11,
"stock": 71,
"status": 1,
"createTime": "2016-11-20 14:21:53",
"updateTime": "2016-11-20 14:21:53"
}
}
5.產(chǎn)品上下架
http://localhost:8080/manage/product/set_sale_status.do?productId=1&status=1
/manage/product/set_sale_status.do
request
productId
status
response
success
{
"status": 0,
"data": "修改產(chǎn)品狀態(tài)成功"
}
6.新增OR更新產(chǎn)品
新增
新增
http://localhost:8080/manage/product/save.do?categoryId=1&name=三星洗衣機(jī)&subtitle=三星大促銷&subImages=test.jpg,11.jpg,2.jpg,3.jpg&detail=detailtext&price=1000&stock=100&status=1
更新
http://localhost:8080/manage/product/save.do?categoryId=1&name=三星洗衣機(jī)&subtitle=三星大促銷&subImages=test.jpg&detail=detailtext&price=1000&stock=100&status=1&id=3
/manage/product/save.do
request
categoryId=1&name=三星洗衣機(jī)&subtitle=三星大促銷&mainImage=sss.jpg&subImages=test.jpg&detail=detailtext&price=1000&stock=100&status=1&id=3
response
success
{
"status": 0,
"data": "更新產(chǎn)品成功"
}
7.富文本上傳圖片
/manage/product/richtext_img_upload.do
request
<form name="form2" action="/manage/product/upload.do" method="post" enctype="multipart/form-data">
<input type="file" name="upload_file">
<input type="submit" value="upload"/>
</form>
response
success
{
"file_path": "http://img.happymmall.com/5fb239f2-0007-40c1-b8e6-0dc11b22779c.jpg",
"msg": "上傳成功",
"success": true
}