how2j.cn

下载区
文件名 文件大小
请先登录 430k
增值内容 430k
430k
使用站长秘制下载工具
步骤 1 : 先运行,看到效果,再学习   
步骤 2 : 模仿和排错   
步骤 3 : 页面效果   
步骤 4 : 5个Comparator比较器   
步骤 5 : ForeRESTController.category()   
步骤 6 : category.html   
步骤 7 : categoryPage.html   
步骤 8 : sortBar.html   
步骤 9 : productsByCategory.html   

步骤 1 :

先运行,看到效果,再学习

edit edit
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
页面效果
步骤 4 :

5个Comparator比较器

edit edit
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package com.how2java.tmall.comparator; import java.util.Comparator; import com.how2java.tmall.pojo.Product; public class ProductAllComparator implements Comparator<Product>{ @Override public int compare(Product p1, Product p2) { return p2.getReviewCount()*p2.getSaleCount()-p1.getReviewCount()*p1.getSaleCount(); } }
package com.how2java.tmall.comparator; import java.util.Comparator; import com.how2java.tmall.pojo.Product; public class ProductDateComparator implements Comparator<Product>{ @Override public int compare(Product p1, Product p2) { return p1.getCreateDate().compareTo(p2.getCreateDate()); } }
package com.how2java.tmall.comparator; import java.util.Comparator; import com.how2java.tmall.pojo.Product; public class ProductPriceComparator implements Comparator<Product> { @Override public int compare(Product p1, Product p2) { return (int) (p1.getPromotePrice()-p2.getPromotePrice()); } }
package com.how2java.tmall.comparator; import java.util.Comparator; import com.how2java.tmall.pojo.Product; public class ProductReviewComparator implements Comparator<Product> { @Override public int compare(Product p1, Product p2) { return p2.getReviewCount()-p1.getReviewCount(); } }
package com.how2java.tmall.comparator; import java.util.Comparator; import com.how2java.tmall.pojo.Product; public class ProductSaleCountComparator implements Comparator<Product> { @Override public int compare(Product p1, Product p2) { return p2.getSaleCount()-p1.getSaleCount(); } }
步骤 5 :

ForeRESTController.category()

edit edit
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
@GetMapping("forecategory/{cid}") public Object category(@PathVariable int cid,String sort) { Category c = categoryService.get(cid); productService.fill(c); productService.setSaleAndReviewNumber(c.getProducts()); categoryService.removeCategoryFromProduct(c); if(null!=sort){ switch(sort){ case "review": Collections.sort(c.getProducts(),new ProductReviewComparator()); break; case "date" : Collections.sort(c.getProducts(),new ProductDateComparator()); break; case "saleCount" : Collections.sort(c.getProducts(),new ProductSaleCountComparator()); break; case "price": Collections.sort(c.getProducts(),new ProductPriceComparator()); break; case "all": Collections.sort(c.getProducts(),new ProductAllComparator()); break; } } return c; }
package com.how2java.tmall.web; import com.how2java.tmall.comparator.*; import com.how2java.tmall.pojo.*; import com.how2java.tmall.service.*; import com.how2java.tmall.util.Result; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.util.HtmlUtils; import javax.servlet.http.HttpSession; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @RestController public class ForeRESTController { @Autowired CategoryService categoryService; @Autowired ProductService productService; @Autowired UserService userService; @Autowired ProductImageService productImageService; @Autowired PropertyValueService propertyValueService; @Autowired OrderItemService orderItemService; @Autowired ReviewService reviewService; @GetMapping("/forehome") public Object home() { List<Category> cs= categoryService.list(); productService.fill(cs); productService.fillByRow(cs); categoryService.removeCategoryFromProduct(cs); return cs; } @PostMapping("/foreregister") public Object register(@RequestBody User user) { String name = user.getName(); String password = user.getPassword(); name = HtmlUtils.htmlEscape(name); user.setName(name); boolean exist = userService.isExist(name); if(exist){ String message ="用户名已经被使用,不能使用"; return Result.fail(message); } user.setPassword(password); userService.add(user); return Result.success(); } @PostMapping("/forelogin") public Object login(@RequestBody User userParam, HttpSession session) { String name = userParam.getName(); name = HtmlUtils.htmlEscape(name); User user =userService.get(name,userParam.getPassword()); if(null==user){ String message ="账号密码错误"; return Result.fail(message); } else{ session.setAttribute("user", user); return Result.success(); } } @GetMapping("/foreproduct/{pid}") public Object product(@PathVariable("pid") int pid) { Product product = productService.get(pid); List<ProductImage> productSingleImages = productImageService.listSingleProductImages(product); List<ProductImage> productDetailImages = productImageService.listDetailProductImages(product); product.setProductSingleImages(productSingleImages); product.setProductDetailImages(productDetailImages); List<PropertyValue> pvs = propertyValueService.list(product); List<Review> reviews = reviewService.list(product); productService.setSaleAndReviewNumber(product); productImageService.setFirstProdutImage(product); Map<String,Object> map= new HashMap<>(); map.put("product", product); map.put("pvs", pvs); map.put("reviews", reviews); return Result.success(map); } @GetMapping("forecheckLogin") public Object checkLogin( HttpSession session) { User user =(User) session.getAttribute("user"); if(null!=user) return Result.success(); return Result.fail("未登录"); } @GetMapping("forecategory/{cid}") public Object category(@PathVariable int cid,String sort) { Category c = categoryService.get(cid); productService.fill(c); productService.setSaleAndReviewNumber(c.getProducts()); categoryService.removeCategoryFromProduct(c); if(null!=sort){ switch(sort){ case "review": Collections.sort(c.getProducts(),new ProductReviewComparator()); break; case "date" : Collections.sort(c.getProducts(),new ProductDateComparator()); break; case "saleCount" : Collections.sort(c.getProducts(),new ProductSaleCountComparator()); break; case "price": Collections.sort(c.getProducts(),new ProductPriceComparator()); break; case "all": Collections.sort(c.getProducts(),new ProductAllComparator()); break; } } return c; } }
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head th:include="include/fore/header::html" ></head> <body> <div id="workingArea"> <div th:replace="include/fore/top::html" ></div> <div th:replace="include/fore/search::html" ></div> <div th:replace="include/fore/category/categoryPage::html" ></div> <div th:replace="include/fore/footer::html" ></div> </div> </body> </html>
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
	<head th:include="include/fore/header::html" ></head>
	<body>
		<div id="workingArea">
			<div th:replace="include/fore/top::html" ></div>	
			<div th:replace="include/fore/search::html" ></div>	
			<div th:replace="include/fore/category/categoryPage::html" ></div>	
			<div th:replace="include/fore/footer::html" ></div>	
		</div>
	</body>
</html>
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
<div th:fragment="html"> <script> $(function(){ var cid = getUrlParms("cid"); var sort = getUrlParms("sort"); var data4Vue = { uri:'forecategory', c:'', sort:'' }; //ViewModel var vue = new Vue({ el: '#workingArea', data: data4Vue, mounted:function(){ //mounted 表示这个 Vue 对象加载成功了 this.load(); }, methods: { load:function(){ this.sort = sort; var url = this.uri+"/"+cid+"?sort="+sort; axios.get(url).then(function(response) { vue.c = response.data; vue.$nextTick(function(){ linkDefaultActions(); }) }); } } }); }) </script> <title>模仿天猫官网-{{c.name}}</title> <div id="category"> <div class="categoryPageDiv"> <img v-if="c.id!=null" :src="'img/category/'+c.id+'.jpg'"> <div th:replace="include/fore/category/sortBar::html" ></div> <div th:replace="include/fore/category/productsByCategory::html" ></div> </div> </div> </div>
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
sortBar.html
<div th:fragment="html"> <script> $(function(){ $("input.sortBarPrice").keyup(function(){ var num= $(this).val(); if(num.length==0){ $("div.productUnit").show(); return; } num = parseInt(num); if(isNaN(num)) num= 1; if(num<=0) num = 1; $(this).val(num); var begin = $("input.beginPrice").val(); var end = $("input.endPrice").val(); if(!isNaN(begin) && !isNaN(end)){ $("div.productUnit").hide(); $("div.productUnit").each(function(){ var price = $(this).attr("price"); price = new Number(price); if(price<=end && price>=begin) $(this).show(); }); } }); }); </script> <div class="categorySortBar"> <table class="categorySortBarTable categorySortTable"> <tr> <td :class="{'grayColumn':(sort==null||sort=='all')}"><a :href="'?cid='+c.id+'&sort=all'">综合<span class="glyphicon glyphicon-arrow-down"></span></a></td> <td :class="{'grayColumn':(sort==null||sort=='review')}"><a :href="'?cid='+c.id+'&sort=review'">人气<span class="glyphicon glyphicon-arrow-down"></span></a></td> <td :class="{'grayColumn':(sort==null||sort=='date')}"><a :href="'?cid='+c.id+'&sort=date'">新品<span class="glyphicon glyphicon-arrow-down"></span></a></td> <td :class="{'grayColumn':(sort==null||sort=='saleCount')}"><a :href="'?cid='+c.id+'&sort=saleCount'">销量<span class="glyphicon glyphicon-arrow-down"></span></a></td> <td :class="{'grayColumn':(sort==null||sort=='price')}"><a :href="'?cid='+c.id+'&sort=price'">价格<span class="glyphicon glyphicon-resize-vertical"></span></a></td> </tr> </table> <table class="categorySortBarTable"> <tr> <td><input class="sortBarPrice beginPrice" type="text" placeholder="请输入"></td> <td class="grayColumn priceMiddleColumn">-</td> <td><input class="sortBarPrice endPrice" type="text" placeholder="请输入"></td> </tr> </table> </div> </div>
步骤 9 :

productsByCategory.html

edit edit
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
productsByCategory.html
<div th:fragment="html"> <div class="categoryProducts"> <div v-for="p in c.products" class="productUnit" :price="p.promotePrice"> <div class="productUnitFrame"> <a :href="'product?pid='+p.id"> <img class="productImage" :src="'img/productSingle_middle/'+p.firstProductImage.id+'.jpg'"> </a> <span class="productPrice">{{p.promotePrice|formatMoneyFilter}} </span> <a class="productLink" :href="'product?pid='+p.id"> {{p.name|subStringFilter(0,50)}} </a> <a class="tmallLink" :href="'product?pid='+p.id">天猫专卖</a> <div class="show1 productInfo"> <span class="monthDeal ">月成交 <span class="productDealNumber">{{p.saleCount}}笔</span></span> <span class="productReview">评价<span class="productReviewNumber">{{p.reviewCount}}</span></span> <span class="wangwang"> <a class="wangwanglink" href="#nowhere"> <img src="img/site/wangwang.png"> </a> </span> </div> </div> </div> <div style="clear:both"></div> </div> </div>


HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。


提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
关于 实践项目-天猫整站Springboot-分类页 的提问

尽量提供截图代码异常信息,有助于分析和解决问题。 也可进本站QQ群交流: 982790551
提问尽量提供完整的代码,环境描述,越是有利于问题的重现,您的问题越能更快得到解答。
对教程中代码有疑问,请提供是哪个步骤,哪一行有疑问,这样便于快速定位问题,提高问题得到解答的速度
在已经存在的几千个提问里,有相当大的比例,是因为使用了和站长不同版本的开发环境导致的,比如 jdk, eclpise, idea, mysql,tomcat 等等软件的版本不一致。
请使用和站长一样的版本,可以节约自己大量的学习时间。 站长把教学中用的软件版本整理了,都统一放在了这里, 方便大家下载: https://how2j.cn/k/helloworld/helloworld-version/1718.html

上传截图