how2j.cn

-->
下载区
文件名 文件大小
请先登录 393k
增值内容 393k
393k

解压rar如果失败,请用5.21版本或者更高版本的winrar

点击下载 winrar5.21
步骤 1 : 先运行,看到效果,再学习   
步骤 2 : 模仿和排错   
步骤 3 : 页面截图   
步骤 4 : ProductImage   
步骤 5 : ProductImageDAO   
步骤 6 : ProductImageService   
步骤 7 : ProductImageController   
步骤 8 : listProductImage.html   
步骤 9 : 查询功能讲解   
步骤 10 : 增加功能讲解   
步骤 11 : 删除功能讲解   
步骤 12 : 编辑和修改   
步骤 13 : Product   
步骤 14 : ProductImageService   
步骤 15 : ProductController   
步骤 16 : listProduct.html   
步骤 17 : 产品缩略图效果   

步骤 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 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
页面截图
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package com.how2java.tmall.pojo; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @Entity @Table(name = "productimage") @JsonIgnoreProperties({ "handler","hibernateLazyInitializer"}) public class ProductImage { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") private int id; @ManyToOne @JoinColumn(name="pid") @JsonBackReference private Product product; private String type; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getType() { return type; } public void setType(String type) { this.type = type; } public Product getProduct() { return product; } public void setProduct(Product product) { this.product = product; } }
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package com.how2java.tmall.dao; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; import com.how2java.tmall.pojo.Product; import com.how2java.tmall.pojo.ProductImage; public interface ProductImageDAO extends JpaRepository<ProductImage,Integer>{ public List<ProductImage> findByProductAndTypeOrderByIdDesc(Product product, String type); }
package com.how2java.tmall.dao;
 
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;

import com.how2java.tmall.pojo.Product;
import com.how2java.tmall.pojo.ProductImage;

public interface ProductImageDAO extends JpaRepository<ProductImage,Integer>{
	public List<ProductImage> findByProductAndTypeOrderByIdDesc(Product product, String type);
	
}
步骤 6 :

ProductImageService

edit
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package com.how2java.tmall.service; import com.how2java.tmall.dao.ProductImageDAO; import com.how2java.tmall.pojo.Product; import com.how2java.tmall.pojo.ProductImage; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service public class ProductImageService { public static final String type_single = "single"; public static final String type_detail = "detail"; @Autowired ProductImageDAO productImageDAO; @Autowired ProductService productService; public void add(ProductImage bean) { productImageDAO.save(bean); } public void delete(int id) { productImageDAO.delete(id); } public ProductImage get(int id) { return productImageDAO.findOne(id); } public List<ProductImage> listSingleProductImages(Product product) { return productImageDAO.findByProductAndTypeOrderByIdDesc(product, type_single); } public List<ProductImage> listDetailProductImages(Product product) { return productImageDAO.findByProductAndTypeOrderByIdDesc(product, type_detail); } public void setFirstProdutImage(Product product) { List<ProductImage> singleImages = listSingleProductImages(product); if(!singleImages.isEmpty()) product.setFirstProductImage(singleImages.get(0)); else product.setFirstProductImage(new ProductImage()); //这样做是考虑到产品还没有来得及设置图片,但是在订单后台管理里查看订单项的对应产品图片。 } public void setFirstProdutImages(List<Product> products) { for (Product product : products) setFirstProdutImage(product); } }
步骤 7 :

ProductImageController

edit
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package com.how2java.tmall.web; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.imageio.ImageIO; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import com.how2java.tmall.pojo.Product; import com.how2java.tmall.pojo.ProductImage; import com.how2java.tmall.service.CategoryService; import com.how2java.tmall.service.ProductImageService; import com.how2java.tmall.service.ProductService; import com.how2java.tmall.util.ImageUtil; @RestController public class ProductImageController { @Autowired ProductService productService; @Autowired ProductImageService productImageService; @Autowired CategoryService categoryService; @GetMapping("/products/{pid}/productImages") public List<ProductImage> list(@RequestParam("type") String type, @PathVariable("pid") int pid) throws Exception { Product product = productService.get(pid); if(ProductImageService.type_single.equals(type)) { List<ProductImage> singles = productImageService.listSingleProductImages(product); return singles; } else if(ProductImageService.type_detail.equals(type)) { List<ProductImage> details = productImageService.listDetailProductImages(product); return details; } else { return new ArrayList<>(); } } @PostMapping("/productImages") public Object add(@RequestParam("pid") int pid, @RequestParam("type") String type, MultipartFile image, HttpServletRequest request) throws Exception { ProductImage bean = new ProductImage(); Product product = productService.get(pid); bean.setProduct(product); bean.setType(type); productImageService.add(bean); String folder = "img/"; if(ProductImageService.type_single.equals(bean.getType())){ folder +="productSingle"; } else{ folder +="productDetail"; } File imageFolder= new File(request.getServletContext().getRealPath(folder)); File file = new File(imageFolder,bean.getId()+".jpg"); String fileName = file.getName(); if(!file.getParentFile().exists()) file.getParentFile().mkdirs(); try { image.transferTo(file); BufferedImage img = ImageUtil.change2jpg(file); ImageIO.write(img, "jpg", file); } catch (IOException e) { e.printStackTrace(); } if(ProductImageService.type_single.equals(bean.getType())){ String imageFolder_small= request.getServletContext().getRealPath("img/productSingle_small"); String imageFolder_middle= request.getServletContext().getRealPath("img/productSingle_middle"); File f_small = new File(imageFolder_small, fileName); File f_middle = new File(imageFolder_middle, fileName); f_small.getParentFile().mkdirs(); f_middle.getParentFile().mkdirs(); ImageUtil.resizeImage(file, 56, 56, f_small); ImageUtil.resizeImage(file, 217, 190, f_middle); } return bean; } @DeleteMapping("/productImages/{id}") public String delete(@PathVariable("id") int id, HttpServletRequest request) throws Exception { ProductImage bean = productImageService.get(id); productImageService.delete(id); String folder = "img/"; if(ProductImageService.type_single.equals(bean.getType())) folder +="productSingle"; else folder +="productDetail"; File imageFolder= new File(request.getServletContext().getRealPath(folder)); File file = new File(imageFolder,bean.getId()+".jpg"); String fileName = file.getName(); file.delete(); if(ProductImageService.type_single.equals(bean.getType())){ String imageFolder_small= request.getServletContext().getRealPath("img/productSingle_small"); String imageFolder_middle= request.getServletContext().getRealPath("img/productSingle_middle"); File f_small = new File(imageFolder_small, fileName); File f_middle = new File(imageFolder_middle, fileName); f_small.delete(); f_middle.delete(); } return null; } }
步骤 8 :

listProductImage.html

edit
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head th:include="include/admin/adminHeader::html('产品管理')" ></head> <body> <div th:replace="include/admin/adminNavigator::html" ></div> <script> $(function(){ var pid = getUrlParms("pid"); var data4Vue = { uri:'productImages', singleProductImages: [], detailProductImages: [], product: '', category:'', singleFile:'', detailFile:'' }; //ViewModel var vue = new Vue({ el: '#workingArea', data: data4Vue, mounted:function(){ //mounted 表示这个 Vue 对象加载成功了 this.listSingles(); this.listDetails(); this.getProduct(pid); }, methods: { getProduct:function(pid){ var url = "products/"+pid; axios.get(url).then(function(response) { vue.product = response.data; vue.category = vue.product.category; }) }, listSingles:function(start){ var url = "products/"+pid+"/"+this.uri+"?type=single"; axios.get(url).then(function(response) { vue.singleProductImages = response.data; }); }, listDetails:function(start){ var url = "products/"+pid+"/"+this.uri+"?type=detail"; axios.get(url).then(function(response) { vue.detailProductImages = response.data; }); }, addSingle: function () { if(!checkEmpty(this.singleFile, "单个产品图片")) return; var url = this.uri+"?type=single&pid="+pid; var formData = new FormData(); formData.append("image", this.singleFile); axios.post(url,formData).then(function(response){ vue.listSingles(); $("#singlePic").val(''); vue.singleFile = null; }); }, addDetail: function () { if(!checkEmpty(this.detailFile, "详情产品图片")) return; var url = this.uri+"?type=detail&pid="+pid; var formData = new FormData(); formData.append("image", this.detailFile); axios.post(url,formData).then(function(response){ vue.listDetails(); $("#detailPic").val(''); vue.detailFile = null; }); }, deleteBean: function (id) { if(!checkDeleteLink()) return; var url = this.uri+"/"+id; axios.delete(url).then(function(response){ vue.listSingles(); vue.listDetails(); }); }, getSingleFile: function (event) { this.singleFile = event.target.files[0]; }, getDetailFile: function (event) { this.detailFile = event.target.files[0]; }, } }); }); </script> <div id="workingArea" > <ol class="breadcrumb"> <li><a href="admin_category_list">所有分类</a></li> <li><a :href="'admin_product_list?cid='+category.id">{{category.name}}</a></li> <li class="active">{{product.name}}</li> <li class="active">产品图片管理</li> </ol> <table class="addPictureTable" align="center"> <tr> <td class="addPictureTableTD"> <div> <div class="panel panel-warning addPictureDiv"> <div class="panel-heading">新增产品<b class="text-primary"> 单个 </b>图片</div> <div class="panel-body"> <table class="addTable"> <tr> <td>请选择本地图片 尺寸400X400 为佳</td> </tr> <tr> <td> <input id="singlePic" type="file" @change="getSingleFile($event)" name="image" /> </td> </tr> <tr class="submitTR"> <td align="center"> <button type="submit" @click="addSingle" class="btn btn-success">提 交</button> </td> </tr> </table> </div> </div> <table class="table table-striped table-bordered table-hover table-condensed"> <thead> <tr class="success"> <th>ID</th> <th>产品单个图片缩略图</th> <th>删除</th> </tr> </thead> <tbody> <tr v-for="pi in singleProductImages"> <td>{{pi.id}}</td> <td> <a title="点击查看原图" :href="'img/productSingle/'+pi.id+'.jpg'"><img height="50px" :src="'img/productSingle/'+pi.id+'.jpg'"></a> </td> <td><a href="#nowhere" @click="deleteBean(pi.id)"><span class="glyphicon glyphicon-trash"></span></a></td> </tr> </tbody> </table> </div> </td> <td class="addPictureTableTD"> <div> <div class="panel panel-warning addPictureDiv"> <div class="panel-heading">新增产品<b class="text-primary"> 详情 </b>图片</div> <div class="panel-body"> <table class="addTable"> <tr> <td>请选择本地图片 宽度790 为佳</td> </tr> <tr> <td> <input id="detailPic" type="file" @change="getDetailFile($event)" name="image" /> </td> </tr> <tr class="submitTR"> <td align="center"> <button type="submit" @click="addDetail" class="btn btn-success">提 交</button> </td> </tr> </table> </div> </div> <table class="table table-striped table-bordered table-hover table-condensed"> <thead> <tr class="success"> <th>ID</th> <th>产品详情图片缩略图</th> <th>删除</th> </tr> </thead> <tbody> <tr v-for="pi in detailProductImages"> <td>{{pi.id}}</td> <td> <a title="点击查看原图" :href="'img/productDetail/'+pi.id+'.jpg'"><img height="50px" :src="'img/productDetail/'+pi.id+'.jpg'"></a> </td> <td><a href="#nowhere" @click="deleteBean(pi.id)"><span class="glyphicon glyphicon-trash"></span></a></td> </tr> </tbody> </table> </div> </td> </tr> </table> </div> <div th:replace="include/admin/adminFooter::html" ></div> </body> </html>
步骤 9 :

查询功能讲解

edit
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
查询功能讲解
@GetMapping("/products/{pid}/productImages") public List<ProductImage> list(@RequestParam("type") String type, @PathVariable("pid") int pid) throws Exception { Product product = productService.get(pid); if(ProductImageService.type_single.equals(type)) { List<ProductImage> singles = productImageService.listSingleProductImages(product); return singles; } else if(ProductImageService.type_detail.equals(type)) { List<ProductImage> details = productImageService.listDetailProductImages(product); return details; } else { return new ArrayList<>(); } }
listSingles:function(start){ var url = "products/"+pid+"/"+this.uri+"?type=single"; axios.get(url).then(function(response) { vue.singleProductImages = response.data; }); },
<tr v-for="pi in singleProductImages"> <td>{{pi.id}}</td> <td> <a title="点击查看原图" :href="'img/productSingle/'+pi.id+'.jpg'"><img height="50px" :src="'img/productSingle/'+pi.id+'.jpg'"></a> </td> <td><a href="#nowhere" @click="deleteBean(pi.id)"><span class="glyphicon glyphicon-trash"></span></a></td> </tr>
步骤 10 :

增加功能讲解

edit
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增加功能讲解
addSingle: function () { if(!checkEmpty(this.singleFile, "单个产品图片")) return; var url = this.uri+"?type=single&pid="+pid; var formData = new FormData(); formData.append("image", this.singleFile); axios.post(url,formData).then(function(response){ vue.listSingles(); $("#singlePic").val(''); vue.singleFile = null; }); },
@PostMapping("/productImages") public Object add(@RequestParam("pid") int pid, @RequestParam("type") String type, MultipartFile image, HttpServletRequest request) throws Exception { ProductImage bean = new ProductImage(); Product product = productService.get(pid); bean.setProduct(product); bean.setType(type); productImageService.add(bean); String folder = "img/"; if(ProductImageService.type_single.equals(bean.getType())){ folder +="productSingle"; } else{ folder +="productDetail"; } File imageFolder= new File(request.getServletContext().getRealPath(folder)); File file = new File(imageFolder,bean.getId()+".jpg"); String fileName = file.getName(); if(!file.getParentFile().exists()) file.getParentFile().mkdirs(); try { image.transferTo(file); BufferedImage img = ImageUtil.change2jpg(file); ImageIO.write(img, "jpg", file); } catch (IOException e) { e.printStackTrace(); } if(ProductImageService.type_single.equals(bean.getType())){ String imageFolder_small= request.getServletContext().getRealPath("img/productSingle_small"); String imageFolder_middle= request.getServletContext().getRealPath("img/productSingle_middle"); File f_small = new File(imageFolder_small, fileName); File f_middle = new File(imageFolder_middle, fileName); f_small.getParentFile().mkdirs(); f_middle.getParentFile().mkdirs(); ImageUtil.resizeImage(file, 56, 56, f_small); ImageUtil.resizeImage(file, 217, 190, f_middle); } return bean; }
步骤 11 :

删除功能讲解

edit
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
删除功能讲解
@DeleteMapping("/productImages/{id}") public String delete(@PathVariable("id") int id, HttpServletRequest request) throws Exception { ProductImage bean = productImageService.get(id); productImageService.delete(id); String folder = "img/"; if(ProductImageService.type_single.equals(bean.getType())) folder +="productSingle"; else folder +="productDetail"; File imageFolder= new File(request.getServletContext().getRealPath(folder)); File file = new File(imageFolder,bean.getId()+".jpg"); String fileName = file.getName(); file.delete(); if(ProductImageService.type_single.equals(bean.getType())){ String imageFolder_small= request.getServletContext().getRealPath("img/productSingle_small"); String imageFolder_middle= request.getServletContext().getRealPath("img/productSingle_middle"); File f_small = new File(imageFolder_small, fileName); File f_middle = new File(imageFolder_middle, fileName); f_small.delete(); f_middle.delete(); } return null; }
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
Product
package com.how2java.tmall.pojo; import java.util.Date; import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import javax.persistence.Transient; import org.springframework.data.elasticsearch.annotations.Document; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @Entity @Table(name = "product") @JsonIgnoreProperties({ "handler","hibernateLazyInitializer"}) @Document(indexName = "tmall_springboot",type = "product") public class Product { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") int id; @ManyToOne @JoinColumn(name="cid") private Category category; //如果既没有指明 关联到哪个Column,又没有明确要用@Transient忽略,那么就会自动关联到表对应的同名字段 private String name; private String subTitle; private float originalPrice; private float promotePrice; private int stock; private Date createDate; @Transient private ProductImage firstProductImage; public int getId() { return id; } public void setId(int id) { this.id = id; } public Category getCategory() { return category; } public void setCategory(Category category) { this.category = category; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSubTitle() { return subTitle; } public void setSubTitle(String subTitle) { this.subTitle = subTitle; } public float getOriginalPrice() { return originalPrice; } public void setOriginalPrice(float originalPrice) { this.originalPrice = originalPrice; } public float getPromotePrice() { return promotePrice; } public void setPromotePrice(float promotePrice) { this.promotePrice = promotePrice; } public int getStock() { return stock; } public void setStock(int stock) { this.stock = stock; } public Date getCreateDate() { return createDate; } public void setCreateDate(Date createDate) { this.createDate = createDate; } public ProductImage getFirstProductImage() { return firstProductImage; } public void setFirstProductImage(ProductImage firstProductImage) { this.firstProductImage = firstProductImage; } }
步骤 14 :

ProductImageService

edit
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package com.how2java.tmall.service; import com.how2java.tmall.dao.ProductImageDAO; import com.how2java.tmall.pojo.Product; import com.how2java.tmall.pojo.ProductImage; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service public class ProductImageService { public static final String type_single = "single"; public static final String type_detail = "detail"; @Autowired ProductImageDAO productImageDAO; @Autowired ProductService productService; public void add(ProductImage bean) { productImageDAO.save(bean); } public void delete(int id) { productImageDAO.delete(id); } public ProductImage get(int id) { return productImageDAO.findOne(id); } public List<ProductImage> listSingleProductImages(Product product) { return productImageDAO.findByProductAndTypeOrderByIdDesc(product, type_single); } public List<ProductImage> listDetailProductImages(Product product) { return productImageDAO.findByProductAndTypeOrderByIdDesc(product, type_detail); } public void setFirstProdutImage(Product product) { List<ProductImage> singleImages = listSingleProductImages(product); if(!singleImages.isEmpty()) product.setFirstProductImage(singleImages.get(0)); else product.setFirstProductImage(new ProductImage()); //这样做是考虑到产品还没有来得及设置图片,但是在订单后台管理里查看订单项的对应产品图片。 } public void setFirstProdutImages(List<Product> products) { for (Product product : products) setFirstProdutImage(product); } }
步骤 15 :

ProductController

edit
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package com.how2java.tmall.web; import com.how2java.tmall.pojo.Product; import com.how2java.tmall.service.CategoryService; import com.how2java.tmall.service.ProductImageService; import com.how2java.tmall.service.ProductService; import com.how2java.tmall.util.Page4Navigator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.util.Date; @RestController public class ProductController { @Autowired ProductService productService; @Autowired CategoryService categoryService; @Autowired ProductImageService productImageService; @GetMapping("/categories/{cid}/products") public Page4Navigator<Product> list(@PathVariable("cid") int cid, @RequestParam(value = "start", defaultValue = "0") int start,@RequestParam(value = "size", defaultValue = "5") int size) throws Exception { start = start<0?0:start; Page4Navigator<Product> page =productService.list(cid, start, size,5 ); productImageService.setFirstProdutImages(page.getContent()); return page; } @GetMapping("/products/{id}") public Product get(@PathVariable("id") int id) throws Exception { Product bean=productService.get(id); return bean; } @PostMapping("/products") public Object add(@RequestBody Product bean) throws Exception { bean.setCreateDate(new Date()); productService.add(bean); return bean; } @DeleteMapping("/products/{id}") public String delete(@PathVariable("id") int id, HttpServletRequest request) throws Exception { productService.delete(id); return null; } @PutMapping("/products") public Object update(@RequestBody Product bean) throws Exception { productService.update(bean); return bean; } }
步骤 16 :

listProduct.html

edit
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head th:include="include/admin/adminHeader::html('产品管理')" ></head> <body> <div th:replace="include/admin/adminNavigator::html" ></div> <script> $(function(){ var cid = getUrlParms("cid"); var data4Vue = { uri:'products', beans: [], bean: {id:0,name:'','subTitle':'','originalPrice':99.98,'promotePrice':19.98,'stock':99,category:{'id':0}}, pagination:{}, category:'' }; //ViewModel var vue = new Vue({ el: '#workingArea', data: data4Vue, mounted:function(){ //mounted 表示这个 Vue 对象加载成功了 this.list(0); this.getCategory(cid); }, methods: { getCategory:function(cid){ var url = "categories/"+cid; axios.get(url).then(function(response) { vue.category = response.data; }) }, list:function(start){ var url = "categories/"+cid+"/"+this.uri+"?start="+start; axios.get(url).then(function(response) { vue.pagination = response.data; vue.beans = response.data.content ; }); }, add: function () { if(!checkEmpty(this.bean.name, "产品名称")) return; if (!checkEmpty(this.bean.subTitle, "小标题")) return; if (!checkNumber(this.bean.originalPrice, "原价格")) return; if (!checkNumber(this.bean.promotePrice, "优惠价格")) return; if (!checkInt(this.bean.stock, "库存")) return; var url = this.uri; this.bean.category.id=cid; axios.post(url,this.bean).then(function(response){ vue.list(0); vue.bean = {id:0,name:'','subTitle':'','originalPrice':99.98,'promotePrice':19.98,'stock':99,category:{'id':0}}; }); }, deleteBean: function (id) { if(!checkDeleteLink()) return; var url = this.uri+"/"+id; axios.delete(url).then(function(response){ if(0!=response.data.length) alert(response.data); else vue.list(0); }); }, jump: function(page){ jump(page,vue); //定义在adminHeader.html 中 }, jumpByNumber: function(start){ jumpByNumber(start,vue); } } }); }); </script> <div id="workingArea" > <ol class="breadcrumb"> <li><a href="admin_category_list">所有分类</a></li> <li><a :href="'admin_product_list?cid='+category.id">{{category.name}}</a></li> <li class="active">产品管理</li> </ol> <div class="listDataTableDiv"> <table class="table table-striped table-bordered table-hover table-condensed"> <thead> <tr class="success"> <th>ID</th> <th>图片</th> <th>产品名称</th> <th>产品小标题</th> <th width="53px">原价格</th> <th width="80px">优惠价格</th> <th width="80px">库存数量</th> <th width="80px">图片管理</th> <th width="80px">设置属性</th> <th>编辑</th> <th>删除</th> </tr> </thead> <tbody> <tr v-for="bean in beans "> <td>{{bean.id}}</td> <td> <img v-if="null != bean.firstProductImage" width="40px" :src="'img/productSingle/'+bean.firstProductImage.id+'.jpg'"> </td> <td>{{bean.name}}</td> <td>{{bean.subTitle}}</td> <td>{{bean.originalPrice}}</td> <td>{{bean.promotePrice}}</td> <td>{{bean.stock}}</td> <td> <a :href="'admin_productImage_list?pid=' + bean.id "><span class="glyphicon glyphicon-picture"></span></a> </td> <td> <a :href="'admin_propertyValue_edit?pid=' + bean.id "><span class="glyphicon glyphicon-th-list"></span></a> </td> <td> <a :href="'admin_product_edit?id=' + bean.id "><span class="glyphicon glyphicon-edit"></span></a> </td> <td> <a href="#nowhere" @click="deleteBean(bean.id)"><span class=" glyphicon glyphicon-trash"></span></a> </td> </tr> </tbody> </table> </div> <div th:replace="include/admin/adminPage::html" ></div> <div class="panel panel-warning addDiv"> <div class="panel-heading">新增产品</div> <div class="panel-body"> <table class="addTable"> <tr> <td>产品名称</td> <td><input @keyup.enter="add" v-model.trim="bean.name" type="text" class="form-control"></td> </tr> <tr> <td>产品小标题</td> <td><input @keyup.enter="add" v-model.trim="bean.subTitle" type="text" class="form-control"></td> </tr> <tr> <td>原价格</td> <td><input @keyup.enter="add" v-model.trim="bean.originalPrice" type="text" class="form-control"></td> </tr> <tr> <td>优惠价格</td> <td><input @keyup.enter="add" v-model.trim="bean.promotePrice" type="text" class="form-control"></td> </tr> <tr> <td>库存</td> <td><input @keyup.enter="add" v-model.trim="bean.stock" type="text" class="form-control"></td> </tr> <tr class="submitTR"> <td colspan="2" align="center"> <a href="#nowhere" @click="add" class="btn btn-success">提交</a> </td> </tr> </table> </div> </div> </div> <div th:replace="include/admin/adminFooter::html" ></div> </body> </html>
步骤 17 :

产品缩略图效果

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


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


问答区域    
2024-03-29 关于之前的提问在service中的setProductImage
lee0315123




之前有个提问是为啥不改一下setProdutImage(少个c),下面回答没看懂
加载中

							

							





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





2024-03-29 源代码问题不是utf-8或gbk的问题
lee0315123




上个问题后,照网上我改了编码格式又改回utf-8,但是还是有问题,我有点菜,看不出哪里的问题 还有问下站长,怎么从spring boot的启动信息准确查找错误位置
加载中
***************************
APPLICATION FAILED TO START
***************************

Description:

The Tomcat connector configured to listen on port 8080 failed to start. The port may already be in use or the connector may be misconfigured.

Action:

Verify the connector's configuration, identify and stop any process that's listening on port 8080, or configure this application to listen on another port.

							





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





2022-02-17 图片添加问题
2021-10-02 产品和产品图片怎么双向引用了????他们没有同时出现把?
2021-06-09 关于listProduct页面第111行图片显示的原理


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

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

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

上传截图