how2j.cn

下载区
文件名 文件大小
请先登录 1m
增值内容 1m
1m
使用站长秘制下载工具
步骤 1 : 先运行,看到效果,再学习   
步骤 2 : 模仿和排错   
步骤 3 : 页面截图   
步骤 4 : Product   
步骤 5 : ProductDAO   
步骤 6 : ProductService   
步骤 7 : ProductController   
步骤 8 : listProduct.html+editProduct.html   
步骤 9 : 功能讲解   
步骤 10 : 自己做一遍   

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

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

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

public interface ProductDAO extends JpaRepository<Product,Integer>{
	Page<Product> findByCategory(Category category, 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; @Service public class ProductService { @Autowired ProductDAO productDAO; @Autowired CategoryService categoryService; 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); } }
增值内容,请先登录
完整的 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.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; @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 ); 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; } }
步骤 8 :

listProduct.html+editProduct.html

edit 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> </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>
<!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 data4Vue = { uri: 'products', listURL:'admin_product_list', bean: '', category:'' }; //ViewModel var vue = new Vue({ el: '#workingArea', data: data4Vue, mounted:function(){ //mounted 表示这个 Vue 对象加载成功了 this.get(); }, methods: { get:function(){ var id = getUrlParms("id"); var url = this.uri+"/"+id; axios.get(url).then(function(response) { vue.bean = response.data; vue.category = vue.bean.category; }) }, update: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; axios.put(url,vue.bean).then(function(response){ location.href=vue.listURL+"?cid="+vue.category.id; }); } } }); }); </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="panel panel-warning editDiv"> <div class="panel-heading">编辑产品</div> <div class="panel-body"> <table class="editTable"> <tr> <td>产品名称</td> <td><input @keyup.enter="update" v-model.trim="bean.name" type="text" class="form-control"></td> </tr> <tr> <td>产品小标题</td> <td><input @keyup.enter="update" v-model.trim="bean.subTitle" type="text" class="form-control"></td> </tr> <tr> <td>原价格</td> <td><input @keyup.enter="update" v-model.trim="bean.originalPrice" type="text" class="form-control"></td> </tr> <tr> <td>优惠价格</td> <td><input @keyup.enter="update" v-model.trim="bean.promotePrice" type="text" class="form-control"></td> </tr> <tr> <td>库存</td> <td><input @keyup.enter="update" v-model.trim="bean.stock" type="text" class="form-control"></td> </tr> <tr class="submitTR"> <td colspan="2" align="center"> <input type="hidden" name="id" v-model.trim="bean.id" > <a href="#nowhere" class="btn btn-success" @click="update">提 交</a> </td> </tr> </table> </div> </div> </div> <div th:replace="include/admin/adminFooter::html" ></div> </body> </html>
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢


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


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

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

上传截图