how2j.cn

下载区
文件名 文件大小
请先登录 431k
增值内容 431k
431k
步骤 1 : 先运行,看到效果,再学习   
步骤 2 : 模仿和排错   
步骤 3 : 界面效果   
步骤 4 : search.html以及simpleSearch.html   
步骤 5 : search.html   
步骤 6 : searchPage.html   
步骤 7 : ForeRESTController.search()   
步骤 8 : ProductDAO   
步骤 9 : ProductService   
步骤 10 : productsBySearch.html   
步骤 11 : 关于 ElasticSearch   

步骤 1 :

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

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 :

search.html以及simpleSearch.html

edit
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
ForePageController片段 @GetMapping(value="/search") public String searchResult(){ return "fore/search"; }
ForePageController片段
	@GetMapping(value="/search")
	public String searchResult(){
		return "fore/search";
	}
增值内容,请先登录
完整的 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/simpleSearch::html" ></div> <div th:replace="include/fore/searchPage::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/simpleSearch::html" ></div>	
			<div th:replace="include/fore/searchPage::html" ></div>	
			<div th:replace="include/fore/footer::html" ></div>	
		</div>
	</body>
</html>
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
<div class th:fragment="html"> <script> $(function(){ var keyword = getUrlParms("keyword"); var data4Vue = { uri:'foresearch', products:[] }; //ViewModel var vue = new Vue({ el: '#workingArea', data: data4Vue, mounted:function(){ //mounted 表示这个 Vue 对象加载成功了 this.load(); }, methods: { load:function(){ var url = this.uri+"?keyword="+keyword; axios.post(url).then(function(response) { vue.products = response.data; vue.$nextTick(function(){ linkDefaultActions(); }) }); } } }); }) </script> <div id="searchResult"> <div class="searchResultDiv"> <div th:replace="include/fore/productsBySearch::html" ></div> </div> </div> </div>
步骤 7 :

ForeRESTController.search()

edit
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
@PostMapping("foresearch") public Object search( String keyword){ if(null==keyword) keyword = ""; List<Product> ps= productService.search(keyword,0,20); productImageService.setFirstProdutImages(ps); productService.setSaleAndReviewNumber(ps); return ps; }
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; } @PostMapping("foresearch") public Object search( String keyword){ if(null==keyword) keyword = ""; List<Product> ps= productService.search(keyword,0,20); productImageService.setFirstProdutImages(ps); productService.setSaleAndReviewNumber(ps); return ps; } }
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package com.how2java.tmall.dao; import com.how2java.tmall.pojo.Category; import com.how2java.tmall.pojo.Product; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; public interface ProductDAO extends JpaRepository<Product,Integer>{ Page<Product> findByCategory(Category category, Pageable pageable); List<Product> findByCategoryOrderById(Category category); List<Product> findByNameLike(String keyword, Pageable pageable); }
package com.how2java.tmall.dao;

import com.how2java.tmall.pojo.Category;
import com.how2java.tmall.pojo.Product;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface ProductDAO extends JpaRepository<Product,Integer>{
	Page<Product> findByCategory(Category category, Pageable pageable);
	List<Product> findByCategoryOrderById(Category category);
	List<Product> findByNameLike(String keyword, Pageable pageable);

}
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package com.how2java.tmall.service; import com.how2java.tmall.dao.ProductDAO; import com.how2java.tmall.pojo.Category; import com.how2java.tmall.pojo.Product; import com.how2java.tmall.util.Page4Navigator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; @Service public class ProductService { @Autowired ProductDAO productDAO; @Autowired CategoryService categoryService; @Autowired ProductImageService productImageService; @Autowired OrderItemService orderItemService; @Autowired ReviewService reviewService; public void add(Product bean) { productDAO.save(bean); } public void delete(int id) { productDAO.delete(id); } public Product get(int id) { return productDAO.findOne(id); } public void update(Product bean) { productDAO.save(bean); } public Page4Navigator<Product> list(int cid, int start, int size,int navigatePages) { Category category = categoryService.get(cid); Sort sort = new Sort(Sort.Direction.DESC, "id"); Pageable pageable = new PageRequest(start, size, sort); Page<Product> pageFromJPA =productDAO.findByCategory(category,pageable); return new Page4Navigator<>(pageFromJPA,navigatePages); } public void fill(List<Category> categorys) { for (Category category : categorys) { fill(category); } } public void fill(Category category) { List<Product> products = listByCategory(category); productImageService.setFirstProdutImages(products); category.setProducts(products); } public void fillByRow(List<Category> categorys) { int productNumberEachRow = 8; for (Category category : categorys) { List<Product> products = category.getProducts(); List<List<Product>> productsByRow = new ArrayList<>(); for (int i = 0; i < products.size(); i+=productNumberEachRow) { int size = i+productNumberEachRow; size= size>products.size()?products.size():size; List<Product> productsOfEachRow =products.subList(i, size); productsByRow.add(productsOfEachRow); } category.setProductsByRow(productsByRow); } } public List<Product> listByCategory(Category category){ return productDAO.findByCategoryOrderById(category); } public void setSaleAndReviewNumber(Product product) { int saleCount = orderItemService.getSaleCount(product); product.setSaleCount(saleCount); int reviewCount = reviewService.getCount(product); product.setReviewCount(reviewCount); } public void setSaleAndReviewNumber(List<Product> products) { for (Product product : products) setSaleAndReviewNumber(product); } public List<Product> search(String keyword, int start, int size) { Sort sort = new Sort(Sort.Direction.DESC, "id"); Pageable pageable = new PageRequest(start, size, sort); List<Product> products =productDAO.findByNameLike("%"+keyword+"%",pageable); return products; } }
步骤 10 :

productsBySearch.html

edit
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
<div class th:fragment="html"> <div class="searchProducts"> <div class="productUnit" price="${p.promotePrice}" v-for="p in products" > <a :href="'product?pid='+p.id"> <img class="productImage" :src="'img/productSingle/'+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"><img src="img/site/wangwang.png"></span> </div> </div> <div v-if="0 == products.length" class="noMatch">没有满足条件的产品</div> <div style="clear:both"></div> </div> </div>
步骤 11 :

关于 ElasticSearch

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


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


问答区域    
2022-01-11 请问站长,前端${application.contentPath}是何时设置的
drlg7530




请问站长,我的项目到现在点首页的图标都不会跳转,<a href="">,获取不到${application.contextPath},我全局搜索没找到设置application,这个值是从哪里取的呢
加载中
<a th:href="${application.contextPath}"><img src="img/site/simpleLogo.png"></a>

							


1 个答案

how2j
答案时间:2022-02-02
在后面环节的拦截器那里设置的: https://how2j.cn/k/tmall_springboot/tmall_springboot-1902/1902.html#step8537



回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到





2021-04-23 simplesearch 中的 searchBelow 是做什么用的
wdfasd




simplesearch 中的 searchBelow 是做什么用的
加载中

							

							


1 个答案

how2j
答案时间:2021-04-24
搜索框下面的内容,后面在拦截器哪里会讲到。



回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到





2020-12-09 那个keyword
2020-06-28 ForeRESTController里面的keywork是怎么获取到的
2020-01-16 站长,搜索框input value 获取参数值问题?


提问太多,页面渲染太慢,为了加快渲染速度,本页最多只显示几条提问。还有 7 条以前的提问,请 点击查看

提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
关于 实践项目-天猫整站Springboot-搜索 的提问

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

上传截图