




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
第Java仿天貓服裝商城系統(tǒng)的實現(xiàn)流程一、項目簡述
功能:網(wǎng)上商城系統(tǒng),前臺+后臺管理,用戶注冊,登錄,上哦展示,分組展示,搜索,收貨地址管理,購物車管理,添加,購買,個人信息修改。訂單查詢等等,后臺商品管理,分類管理,庫存管理,訂單管理,用戶管理,信息、修改等等。
二、項目運行
環(huán)境配置:Jdk1.8+Tomcat8.5+mysql+Eclispe(IntelliJIDEA,Eclispe,MyEclispe,Sts都支持)
項目技術:JSP+Spring+SpringMVC+MyBatis+html+css+JavaScript+JQuery+Ajax+layui+maven等等。
權限控制代碼:
*產(chǎn)品詳情頁
@Controller
publicclassForeProductDetailsControllerextendsBaseController{
@Resource(name="productService")
privateProductServiceproductService;
@Resource(name="userService")
privateUserServiceuserService;
@Resource(name="productImageService")
privateProductImageServiceproductImageService;
@Resource(name="categoryService")
privateCategoryServicecategoryService;
@Resource(name="propertyValueService")
privatePropertyValueServicepropertyValueService;
@Resource(name="propertyService")
privatePropertyServicepropertyService;
@Resource(name="reviewService")
privateReviewServicereviewService;
@Resource(name="productOrderItemService")
privateProductOrderItemServiceproductOrderItemService;
//轉(zhuǎn)到前臺天貓-產(chǎn)品詳情頁
@RequestMapping(value="product/{pid}",method=RequestMethod.GET)
publicStringgoToPage(HttpSessionsession,MapString,Objectmap,
@PathVariable("pid")Stringpid/*產(chǎn)品ID*/){
("檢查用戶是否登錄");
ObjectuserId=checkUser(session);
if(userId!=null){
("獲取用戶信息");
Useruser=userService.get(Integer.parseInt(userId.toString()));
map.put("user",user);
("獲取產(chǎn)品ID");
Integerproduct_id=Integer.parseInt(pid);
("獲取產(chǎn)品信息");
Productproduct=productService.get(product_id);
if(product==null||product.getProduct_isEnabled()==1){
return"redirect:/404";
("獲取產(chǎn)品子信息-分類信息");
product.setProduct_category(categoryService.get(product.getProduct_category().getCategory_id()));
("獲取產(chǎn)品子信息-預覽圖片信息");
ListProductImagesingleProductImageList=productImageService.getList(product_id,(byte)0,null);
product.setSingleProductImageList(singleProductImageList);
("獲取產(chǎn)品子信息-詳情圖片信息");
ListProductImagedetailsProductImageList=productImageService.getList(product_id,(byte)1,null);
product.setDetailProductImageList(detailsProductImageList);
("獲取產(chǎn)品子信息-產(chǎn)品屬性值信息");
ListPropertyValuepropertyValueList=propertyValueService.getList(newPropertyValue().setPropertyValue_product(product),null);
("獲取產(chǎn)品子信息-分類信息對應的屬性列表");
ListPropertypropertyList=propertyService.getList(newProperty().setProperty_category(product.getProduct_category()),null);
("屬性列表和屬性值列表合并");
for(Propertyproperty:propertyList){
for(PropertyValuepropertyValue:propertyValueList){
if(property.getProperty_id().equals(propertyValue.getPropertyValue_property().getProperty_id())){
ListPropertyValueproperty_value_item=newArrayList(1);
property_value_item.add(propertyValue);
property.setPropertyValueList(property_value_item);
break;
("獲取產(chǎn)品子信息-產(chǎn)品評論信息");
product.setReviewList(reviewService.getListByProductId(product_id,null));
if(product.getReviewList()!=null){
for(Reviewreview:product.getReviewList()){
review.setReview_user(userService.get(review.getReview_user().getUser_id()));
("獲取猜你喜歡列表");
Integercategory_id=product.getProduct_category().getCategory_id();
Integertotal=productService.getTotal(newProduct().setProduct_category(newCategory().setCategory_id(category_id)),newByte[]{0,2});
("分類ID為{}的產(chǎn)品總數(shù)為{}條",category_id,total);
//生成隨機數(shù)
inti=newRandom().nextInt(total);
if(i+2=total){
i=total-3;
if(i0){
i=0;
ListProductloveProductList=productService.getList(newProduct().setProduct_category(
newCategory().setCategory_id(category_id)),
newByte[]{0,2},
null,
newPageUtil().setCount(3).setPageStart(i)
if(loveProductList!=null){
("獲取產(chǎn)品列表的相應的一張預覽圖片");
for(ProductloveProduct:loveProductList){
loveProduct.setSingleProductImageList(productImageService.getList(loveProduct.getProduct_id(),(byte)0,newPageUtil(0,1)));
("獲取分類列表");
ListCategorycategoryList=categoryService.getList(null,newPageUtil(0,3));
map.put("loveProductList",loveProductList);
map.put("categoryList",categoryList);
map.put("propertyList",propertyList);
map.put("product",product);
map.put("guessNumber",i);
map.put("pageUtil",newPageUtil(0,10).setTotal(product.getProduct_review_count()));
("轉(zhuǎn)到前臺-產(chǎn)品詳情頁");
return"fore/productDetailsPage";
//按產(chǎn)品ID加載產(chǎn)品評論列表-ajax
@Deprecated
@ResponseBody
@RequestMapping(value="review/{pid}",method=RequestMethod.GET,produces="application/json;charset=utf-8")
publicStringloadProductReviewList(@PathVariable("pid")Stringpid/*產(chǎn)品ID*/,
@RequestParamIntegerindex/*頁數(shù)*/,
@RequestParamIntegercount/*行數(shù)*/){
("獲取產(chǎn)品ID");
Integerproduct_id=Integer.parseInt(pid);
("獲取產(chǎn)品評論列表");
ListReviewreviewList=reviewService.getListByProductId(product_id,newPageUtil(index,count));
JSONObjectjsonObject=newJSONObject();
jsonObject.put("reviewList",JSONArray.parseArray(JSON.toJSONString(reviewList)));
returnjsonObject.toJSONString();
//按產(chǎn)品ID加載產(chǎn)品屬性列表-ajax
@Deprecated
@ResponseBody
@RequestMapping(value="property/{pid}",method=RequestMethod.GET,produces="application/json;charset=utf-8")
publicStringloadProductPropertyList(@PathVariable("pid")Stringpid/*產(chǎn)品ID*/){
("獲取產(chǎn)品ID");
Integerproduct_id=Integer.parseInt(pid);
("獲取產(chǎn)品詳情-屬性值信息");
Productproduct=newProduct();
product.setProduct_id(product_id);
ListPropertyValuepropertyValueList=propertyValueService.getList(newPropertyValue().setPropertyValue_product(product),null);
("獲取產(chǎn)品詳情-分類信息對應的屬性列表");
ListPropertypropertyList=propertyService.getList(newProperty().setProperty_category(product.getProduct_category()),null);
("屬性列表和屬性值列表合并");
for(Propertyproperty:propertyList){
for(PropertyValuepropertyValue:propertyValueList){
if(property.getProperty_id().equals(propertyValue.getPropertyValue_property().getProperty_id())){
ListPropertyValueproperty_value_item=newArrayList(1);
property_value_item.add(propertyValue);
property.setPropertyValueList(property_value_item);
break;
JSONObjectjsonObject=newJSONObject();
jsonObject.put("propertyList",JSONArray.parseArray(JSON.toJSONString(propertyList)));
returnjsonObject.toJSONString();
//加載猜你喜歡列表-ajax
@ResponseBody
@RequestMapping(value="guess/{cid}",method=RequestMethod.GET,produces="application/json;charset=utf-8")
publicStringguessYouLike(@PathVariable("cid")Integercid,@RequestParamIntegerguessNumber){
("獲取猜你喜歡列表");
Integertotal=productService.getTotal(newProduct().setProduct_category(newCategory().setCategory_id(cid)),newByte[]{0,2});
("分類ID為{}的產(chǎn)品總數(shù)為{}條",cid,total);
//生成隨機數(shù)
inti=newRandom().nextInt(total);
if(i+2=total){
i=total-3;
if(i0){
i=0;
while(i==guessNumber){
i=newRandom().nextInt(total);
if(i+2=total){
i=total-3;
if(i0){
i=0;
break;
("guessNumber值為{},新guessNumber值為{}",guessNumber,i);
ListProductloveProductList=productService.getList(newProduct().setProduct_category(
newCategory().setCategory_id(cid)),
newByte[]{0,2},
null,
newPageUtil().setCount(3).setPageStart(i)
if(loveProductList!=null){
("獲取產(chǎn)品列表的相應的一張預覽圖片");
for(ProductloveProduct:loveProductList){
loveProduct.setSingleProductImageList(productImageService.getList(loveProduct.getProduct_id(),(byte)0,newPageUtil(0,1)));
JSONObjectjsonObject=newJSONObject();
("獲取數(shù)據(jù)成功!");
jsonObject.put("success",true);
jsonObject.put("loveProductList",JSONArray.parseArray(JSON.toJSONString(loveProductList)));
jsonObject.put("guessNumber",i);
returnjsonObject.toJSONString();
}
用戶信息管理控制層:
*用戶信息管理
@Controller
publicclassForeUserControllerextendsBaseController{
@Resource(name="addressService")
privateAddressServiceaddressService;
@Resource(name="userService")
privateUserServiceuserService;
//轉(zhuǎn)到前臺天貓-用戶詳情頁
@RequestMapping(value="userDetails",method=RequestMethod.GET)
publicStringgoToUserDetail(HttpSessionsession,MapString,Objectmap){
("檢查用戶是否登錄");
ObjectuserId=checkUser(session);
if(userId!=null){
("獲取用戶信息");
Useruser=userService.get(Integer.parseInt(userId.toString()));
map.put("user",user);
("獲取用戶所在地區(qū)級地址");
StringdistrictAddressId=user.getUser_address().getAddress_areaId();
AddressdistrictAddress=addressService.get(districtAddressId);
("獲取市級地址信息");
AddresscityAddress=addressService.get(districtAddress.getAddress_regionId().getAddress_areaId());
("獲取其他地址信息");
ListAddressaddressList=addressService.getRoot();
ListAddresscityList=addressService.getList(
null,cityAddress.getAddress_regionId().getAddress_areaId()
ListAddressdistrictList=addressService.getList(null,cityAddress.getAddress_areaId());
map.put("addressList",addressList);
map.put("cityList",cityList);
map.put("districtList",districtList);
map.put("addressId",cityAddress.getAddress_regionId().getAddress_areaId());
map.put("cityAddressId",cityAddress.getAddress_areaId());
map.put("districtAddressId",districtAddressId);
return"fore/userDetails";
}else{
return"redirect:/login";
//前臺天貓-用戶更換頭像
@ResponseBody
@RequestMapping(value="user/uploadUserHeadImage",method=RequestMethod.POST,produces="application/json;charset=utf-8")
publicStringuploadUserHeadImage(@RequestParamMultipartFilefile,HttpSessionsession
StringoriginalFileName=file.getOriginalFilename();
("獲取圖片原始文件名:{}",originalFileName);
Stringextension=originalFileName.substring(originalFileName.lastIndexOf('.'));
StringfileName=UUID.randomUUID()+extension;
StringfilePath=session.getServletContext().getRealPath("/")+"res/images/item/userProfilePicture/"+fileName;
("文件上傳路徑:{}",filePath);
JSONObjectjsonObject=newJSONObject();
try{
("文件上傳中...");
file.transferTo(newFile(filePath));
("文件上傳成功!");
jsonObject.put("success",true);
jsonObject.put("fileName",fileName);
}catch(IOExceptione){
logger.warn("文件上傳失??!");
e.printStackTrace();
jsonObject.put("success",false);
returnjsonObject.toJSONString();
//前臺天貓-用戶詳情更新
@RequestMapping(value="user/update",method=RequestMethod.POST,produces="application/json;charset=utf-8")
publicStringuserUpdate(HttpSessionsession,MapString,Objectmap,
@RequestParam(value="user_nickname")Stringuser_nickname/*用戶昵稱*/,
@RequestParam(value="user_realname")Stringuser_realname/*真實姓名*/,
@RequestParam(value="user_gender")Stringuser_gender/*用戶性別*/,
@RequestParam(value="user_birthday")Stringuser_birthday/*用戶生日*/,
@RequestParam(value="user_address")Stringuser_address/*用戶所在地*/,
@RequestParam(value="user_profile_picture_src",required=false)
Stringuser_profile_picture_src/*用戶頭像*/,
@RequestParam(value="user_password")Stringuser_password/*用戶密碼*/
)throwsParseException,UnsupportedEncodingException{
("檢查用戶是否登錄");
ObjectuserId=checkUser(session);
if(userId!=null){
("獲取用戶信息");
Useruser=userService.get(Integer.parseInt(userId.toString()));
map.put("user",user);
}else{
return"redirect:/login";
("創(chuàng)建用戶對象");
if(user_profile_picture_src!=null"".equals(user_profile_picture_src)){
user_profile_picture_src=null;
UseruserUpdate=newUser()
.setUser_id(Integer.parseInt(userId.toString()))
.setUser_nickname(user_nickname)
.setUser_realname(user_realname)
.setUser_gender(Byte.valueOf(user_gender))
.setUser_b
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 《關鍵有機合成反應機理》課件
- 《新能源汽車基礎術語》課件
- 《SP活動策劃及執(zhí)行》課件
- 《護理專業(yè)介紹》課件
- 《數(shù)字文件管理學研究》課件
- 《糖尿病概述》課件
- 《GBT29186.6-2021品牌價值要素評價第6部分:無形要素》(2025版)深度解析
- 課堂管理情緒書籍分享
- 交通安全講座
- 《蘇寧易購店長管理實務》課件
- 農(nóng)戶貸款管理辦法銀監(jiān)發(fā)〔2012〕50號
- 兒科-補液-液體療法課件
- 康復治療技術運動療法課件
- 專題十二堅定文化自信建設文化強國
- 下肢深靜脈血栓形成患者的護理課件
- 儀控聯(lián)鎖調(diào)試記錄
- 青島版五四制五年級下冊數(shù)學課件 求實際距離
- 智能農(nóng)業(yè)監(jiān)測系統(tǒng)設計 畢業(yè)論文
- DB2101∕T 0010-2019 沈陽市住宅建筑綠色設計標準
- 企業(yè)公司組織架構(gòu)圖word模板
- 《桃樹夏季管理》ppt課件
評論
0/150
提交評論