how2j.cn

下载区
文件名 文件大小
请先登录 34m
增值内容 34m
34m
请先登录 558k
增值内容 558k
558k
请先登录 455k
增值内容 455k
455k

24分34秒
本视频采用html5方式播放,如无法正常播放,请将浏览器升级至最新版本,推荐火狐,chrome,360浏览器。 如果装有迅雷,播放视频呈现直接下载状态,请调整 迅雷系统设置-基本设置-启动-监视全部浏览器 (去掉这个选项)。 chrome 的 视频下载插件会影响播放,如 IDM 等,请关闭或者切换其他浏览器

步骤 1 : Redis 概念   
步骤 2 : Redis 服务器   
步骤 3 : Redis 图形界面客户端   
步骤 4 : Redis配置   
步骤 5 : PortUtil   
步骤 6 : Application   
步骤 7 : application.properties   
步骤 8 : CategoryService 缓存配置   
步骤 9 : 客户端观察数据   
步骤 10 : ProductService 和 SpringContextUtil   
步骤 11 : 其他 Service   
步骤 12 : 可运行项目   

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

Redis 图形界面客户端

edit
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
Redis配置
package com.how2java.tmall.config; import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.cache.RedisCacheManager; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.databind.ObjectMapper; @Configuration //Redis 缓存配置类 public class RedisConfig extends CachingConfigurerSupport { @Bean public CacheManager cacheManager(RedisTemplate<?,?> redisTemplate) { RedisSerializer stringSerializer = new StringRedisSerializer(); Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); ObjectMapper om = new ObjectMapper(); om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.PUBLIC_ONLY); om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); jackson2JsonRedisSerializer.setObjectMapper(om); redisTemplate.setKeySerializer(stringSerializer); redisTemplate.setHashKeySerializer(stringSerializer); redisTemplate.setValueSerializer(jackson2JsonRedisSerializer); redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer); CacheManager cacheManager = new RedisCacheManager(redisTemplate); return cacheManager; } }
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package com.how2java.tmall.util; import java.io.IOException; import java.net.ServerSocket; import javax.swing.JOptionPane; public class PortUtil { public static boolean testPort(int port) { try { ServerSocket ss = new ServerSocket(port); ss.close(); return false; } catch (java.net.BindException e) { return true; } catch (IOException e) { return true; } } public static void checkPort(int port, String server, boolean shutdown) { if(!testPort(port)) { if(shutdown) { String message =String.format("在端口 %d 未检查得到 %s 启动%n",port,server); JOptionPane.showMessageDialog(null, message); System.exit(1); } else { String message =String.format("在端口 %d 未检查得到 %s 启动%n,是否继续?",port,server); if(JOptionPane.OK_OPTION != JOptionPane.showConfirmDialog(null, message)) System.exit(1); } } } }
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package com.how2java.tmall; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.boot.web.support.SpringBootServletInitializer; import org.springframework.cache.annotation.EnableCaching; import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import com.how2java.tmall.util.PortUtil; @SpringBootApplication @EnableCaching public class Application { static { PortUtil.checkPort(6379,"Redis 服务端",true); } public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
步骤 7 :

application.properties

edit
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
#database spring.datasource.url=jdbc:mysql://127.0.0.1:3306/tmall_springboot?characterEncoding=UTF-8 spring.datasource.username=root spring.datasource.password=admin spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.jpa.hibernate.ddl-auto = none #thymeleaf spring.thymeleaf.mode=LEGACYHTML5 spring.thymeleaf.encoding=UTF-8 spring.thymeleaf.content-type=text/html spring.thymeleaf.cache=false #context server.context-path=/tmall_springboot #设置上传文件大小,默认只有1 m spring.http.multipart.maxFileSize=100Mb spring.http.multipart.maxRequestSize=100Mb #jpa对实体类的默认字段会把驼峰命名的属性,转换为字段名的时候自动加上下划线。 这个配置的作用就是去掉下划线 #比如属性名称是 createDate, jpa 默认转换为字段名 create_Date。 有了这个配置之后,就会转换为同名字段 createDate spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl #显示 hibernate运行的 sql 语句 spring.jpa.show-sql=true #Redis数据库索引(默认为0) spring.redis.database=0 #Redis服务器地址 spring.redis.host=127.0.0.1 #Redis服务器连接端口 spring.redis.port=6379 #Redis服务器连接密码(默认为空) spring.redis.password= #连接池最大连接数(使用负值表示没有限制) spring.redis.pool.max-active=10 #连接池最大阻塞等待时间(使用负值表示没有限制) spring.redis.pool.max-wait=-1 #连接池中的最大空闲连接 spring.redis.pool.max-idle=8 #连接池中的最小空闲连接 spring.redis.pool.min-idle=0 #连接超时时间(毫秒) spring.redis.timeout=0
步骤 8 :

CategoryService 缓存配置

edit
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
CategoryService 缓存配置
package com.how2java.tmall.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; 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 com.how2java.tmall.dao.CategoryDAO; import com.how2java.tmall.pojo.Category; import com.how2java.tmall.pojo.Product; import com.how2java.tmall.util.Page4Navigator; @Service @CacheConfig(cacheNames="categories") public class CategoryService { @Autowired CategoryDAO categoryDAO; @CacheEvict(allEntries=true) // @CachePut(key="'category-one-'+ #p0") public void add(Category bean) { categoryDAO.save(bean); } @CacheEvict(allEntries=true) // @CacheEvict(key="'category-one-'+ #p0") public void delete(int id) { categoryDAO.delete(id); } @Cacheable(key="'categories-one-'+ #p0") public Category get(int id) { Category c= categoryDAO.findOne(id); return c; } @CacheEvict(allEntries=true) // @CachePut(key="'category-one-'+ #p0") public void update(Category bean) { categoryDAO.save(bean); } @Cacheable(key="'categories-page-'+#p0+ '-' + #p1") public Page4Navigator<Category> list(int start, int size, int navigatePages) { Sort sort = new Sort(Sort.Direction.DESC, "id"); Pageable pageable = new PageRequest(start, size,sort); Page pageFromJPA =categoryDAO.findAll(pageable); return new Page4Navigator<>(pageFromJPA,navigatePages); } @Cacheable(key="'categories-all'") public List<Category> list() { Sort sort = new Sort(Sort.Direction.DESC, "id"); return categoryDAO.findAll(sort); } //这个方法的用处是删除Product对象上的 分类。 为什么要删除呢? 因为在对分类做序列还转换为 json 的时候,会遍历里面的 products, 然后遍历出来的产品上,又会有分类,接着就开始子子孙孙无穷溃矣地遍历了,就搞死个人了 //而在这里去掉,就没事了。 只要在前端业务上,没有通过产品获取分类的业务,去掉也没有关系 public void removeCategoryFromProduct(List<Category> cs) { for (Category category : cs) { removeCategoryFromProduct(category); } } public void removeCategoryFromProduct(Category category) { List<Product> products =category.getProducts(); if(null!=products) { for (Product product : products) { product.setCategory(null); } } List<List<Product>> productsByRow =category.getProductsByRow(); if(null!=productsByRow) { for (List<Product> ps : productsByRow) { for (Product p: ps) { p.setCategory(null); } } } } }
步骤 9 :

客户端观察数据

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

ProductService 和 SpringContextUtil

edit
增值内容,请先登录
完整的 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 com.how2java.tmall.util.SpringContextUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; 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 @CacheConfig(cacheNames="products") public class ProductService { @Autowired ProductDAO productDAO; @Autowired ProductImageService productImageService; @Autowired CategoryService categoryService; @Autowired OrderItemService orderItemService; @Autowired ReviewService reviewService; @CacheEvict(allEntries=true) public void add(Product bean) { productDAO.save(bean); } @CacheEvict(allEntries=true) public void delete(int id) { productDAO.delete(id); } @Cacheable(key="'products-one-'+ #p0") public Product get(int id) { return productDAO.findOne(id); } @CacheEvict(allEntries=true) public void update(Product bean) { productDAO.save(bean); } @Cacheable(key="'products-cid-'+#p0+'-page-'+#p1 + '-' + #p2 ") 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); } } @Cacheable(key="'products-cid-'+ #p0.id") public List<Product> listByCategory(Category category){ return productDAO.findByCategoryOrderById(category); } public void fill(Category category) { ProductService productService = SpringContextUtil.getBean(ProductService.class); List<Product> products = productService.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 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; } }
package com.how2java.tmall.util; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; import com.how2java.tmall.service.OrderService; @Component public class SpringContextUtil implements ApplicationContextAware { private SpringContextUtil() { } private static ApplicationContext applicationContext; @Override public void setApplicationContext(ApplicationContext applicationContext){ SpringContextUtil.applicationContext = applicationContext; } public static <T> T getBean(Class<T> clazz) { return applicationContext.getBean(clazz); } }
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package com.how2java.tmall.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import com.how2java.tmall.dao.OrderItemDAO; import com.how2java.tmall.pojo.Order; import com.how2java.tmall.pojo.OrderItem; import com.how2java.tmall.pojo.Product; import com.how2java.tmall.pojo.User; import com.how2java.tmall.util.SpringContextUtil; @Service @CacheConfig(cacheNames="orderItems") public class OrderItemService { @Autowired OrderItemDAO orderItemDAO; @Autowired ProductImageService productImageService; public void fill(List<Order> orders) { for (Order order : orders) fill(order); } @CacheEvict(allEntries=true) public void update(OrderItem orderItem) { orderItemDAO.save(orderItem); } public void fill(Order order) { OrderItemService orderItemService = SpringContextUtil.getBean(OrderItemService.class); List<OrderItem> orderItems = orderItemService.listByOrder(order); float total = 0; int totalNumber = 0; for (OrderItem oi :orderItems) { total+=oi.getNumber()*oi.getProduct().getPromotePrice(); totalNumber+=oi.getNumber(); productImageService.setFirstProdutImage(oi.getProduct()); } order.setTotal(total); order.setOrderItems(orderItems); order.setTotalNumber(totalNumber); order.setOrderItems(orderItems); } @CacheEvict(allEntries=true) public void add(OrderItem orderItem) { orderItemDAO.save(orderItem); } @Cacheable(key="'orderItems-one-'+ #p0") public OrderItem get(int id) { return orderItemDAO.findOne(id); } @CacheEvict(allEntries=true) public void delete(int id) { orderItemDAO.delete(id); } public int getSaleCount(Product product) { OrderItemService orderItemService = SpringContextUtil.getBean(OrderItemService.class); List<OrderItem> ois =orderItemService.listByProduct(product); int result =0; for (OrderItem oi : ois) { if(null!=oi.getOrder()) if(null!= oi.getOrder() && null!=oi.getOrder().getPayDate()) result+=oi.getNumber(); } return result; } @Cacheable(key="'orderItems-uid-'+ #p0.id") public List<OrderItem> listByUser(User user) { return orderItemDAO.findByUserAndOrderIsNull(user); } @Cacheable(key="'orderItems-pid-'+ #p0.id") public List<OrderItem> listByProduct(Product product) { return orderItemDAO.findByProduct(product); } @Cacheable(key="'orderItems-oid-'+ #p0.id") public List<OrderItem> listByOrder(Order order) { return orderItemDAO.findByOrderOrderByIdDesc(order); } }
package com.how2java.tmall.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; 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 org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import com.how2java.tmall.dao.OrderDAO; import com.how2java.tmall.pojo.Order; import com.how2java.tmall.pojo.OrderItem; import com.how2java.tmall.pojo.User; import com.how2java.tmall.util.Page4Navigator; import com.how2java.tmall.util.SpringContextUtil; @Service @CacheConfig(cacheNames="orders") public class OrderService { public static final String waitPay = "waitPay"; public static final String waitDelivery = "waitDelivery"; public static final String waitConfirm = "waitConfirm"; public static final String waitReview = "waitReview"; public static final String finish = "finish"; public static final String delete = "delete"; @Autowired OrderDAO orderDAO; @Autowired OrderItemService orderItemService; public List<Order> listByUserWithoutDelete(User user) { OrderService orderService = SpringContextUtil.getBean(OrderService.class); List<Order> orders = orderService.listByUserAndNotDeleted(user); orderItemService.fill(orders); return orders; } @Cacheable(key="'orders-uid-'+ #p0.id") public List<Order> listByUserAndNotDeleted(User user) { return orderDAO.findByUserAndStatusNotOrderByIdDesc(user, OrderService.delete); } @CacheEvict(allEntries=true) public void update(Order bean) { orderDAO.save(bean); } @Cacheable(key="'orders-page-'+#p0+ '-' + #p1") public Page4Navigator<Order> list(int start, int size, int navigatePages) { Sort sort = new Sort(Sort.Direction.DESC, "id"); Pageable pageable = new PageRequest(start, size,sort); Page pageFromJPA =orderDAO.findAll(pageable); return new Page4Navigator<>(pageFromJPA,navigatePages); } @CacheEvict(allEntries=true) public void add(Order order) { orderDAO.save(order); } @CacheEvict(allEntries=true) @Transactional(propagation= Propagation.REQUIRED,rollbackForClassName="Exception") public float add(Order order, List<OrderItem> ois) { float total = 0; add(order); if(false) throw new RuntimeException(); for (OrderItem oi: ois) { oi.setOrder(order); orderItemService.update(oi); total+=oi.getProduct().getPromotePrice()*oi.getNumber(); } return total; } @Cacheable(key="'orders-one-'+ #p0") public Order get(int oid) { return orderDAO.findOne(oid); } public void cacl(Order o) { List<OrderItem> orderItems = o.getOrderItems(); float total = 0; for (OrderItem orderItem : orderItems) { total+=orderItem.getProduct().getPromotePrice()*orderItem.getNumber(); } o.setTotal(total); } public void removeOrderFromOrderItem(List<Order> orders) { for (Order order : orders) { removeOrderFromOrderItem(order); } } public void removeOrderFromOrderItem(Order order) { List<OrderItem> orderItems= order.getOrderItems(); for (OrderItem orderItem : orderItems) { orderItem.setOrder(null); } } }
package com.how2java.tmall.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import com.how2java.tmall.dao.ProductImageDAO; import com.how2java.tmall.pojo.OrderItem; import com.how2java.tmall.pojo.Product; import com.how2java.tmall.pojo.ProductImage; import com.how2java.tmall.util.SpringContextUtil; @Service @CacheConfig(cacheNames="productImages") public class ProductImageService { public static final String type_single = "single"; public static final String type_detail = "detail"; @Autowired ProductImageDAO productImageDAO; @Autowired ProductService productService; @Autowired CategoryService categoryService; @Cacheable(key="'productImages-one-'+ #p0") public ProductImage get(int id) { return productImageDAO.findOne(id); } public void setFirstProdutImage(Product product) { ProductImageService productImageService = SpringContextUtil.getBean(ProductImageService.class); List<ProductImage> singleImages = productImageService.listSingleProductImages(product); if(!singleImages.isEmpty()) product.setFirstProductImage(singleImages.get(0)); else product.setFirstProductImage(new ProductImage()); //这样做是考虑到产品还没有来得及设置图片,但是在订单后台管理里查看订单项的对应产品图片。 } @CacheEvict(allEntries=true) public void add(ProductImage bean) { productImageDAO.save(bean); } @CacheEvict(allEntries=true) public void delete(int id) { productImageDAO.delete(id); } @Cacheable(key="'productImages-single-pid-'+ #p0.id") public List<ProductImage> listSingleProductImages(Product product) { return productImageDAO.findByProductAndTypeOrderByIdDesc(product, type_single); } @Cacheable(key="'productImages-detail-pid-'+ #p0.id") public List<ProductImage> listDetailProductImages(Product product) { return productImageDAO.findByProductAndTypeOrderByIdDesc(product, type_detail); } public void setFirstProdutImages(List<Product> products) { for (Product product : products) setFirstProdutImage(product); } public void setFirstProdutImagesOnOrderItems(List<OrderItem> ois) { for (OrderItem orderItem : ois) { setFirstProdutImage(orderItem.getProduct()); } } }
package com.how2java.tmall.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; 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 com.how2java.tmall.dao.PropertyDAO; import com.how2java.tmall.pojo.Category; import com.how2java.tmall.pojo.Property; import com.how2java.tmall.util.Page4Navigator; @Service @CacheConfig(cacheNames="properties") public class PropertyService { @Autowired PropertyDAO propertyDAO; @Autowired CategoryService categoryService; @CacheEvict(allEntries=true) public void add(Property bean) { propertyDAO.save(bean); } @CacheEvict(allEntries=true) public void delete(int id) { propertyDAO.delete(id); } @Cacheable(key="'properties-one-'+ #p0") public Property get(int id) { return propertyDAO.findOne(id); } @CacheEvict(allEntries=true) public void update(Property bean) { propertyDAO.save(bean); } @Cacheable(key="'properties-cid-'+ #p0.id") public List<Property> listByCategory(Category category){ return propertyDAO.findByCategory(category); } @Cacheable(key="'properties-cid-'+#p0+'-page-'+#p1 + '-' + #p2 ") public Page4Navigator<Property> 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<Property> pageFromJPA =propertyDAO.findByCategory(category,pageable); return new Page4Navigator<>(pageFromJPA,navigatePages); } }
package com.how2java.tmall.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import com.how2java.tmall.dao.PropertyValueDAO; import com.how2java.tmall.pojo.Product; import com.how2java.tmall.pojo.Property; import com.how2java.tmall.pojo.PropertyValue; import com.how2java.tmall.util.SpringContextUtil; @Service @CacheConfig(cacheNames="propertyValues") public class PropertyValueService { @Autowired PropertyValueDAO propertyValueDAO; @Autowired PropertyService propertyService; @CacheEvict(allEntries=true) public void update(PropertyValue bean) { propertyValueDAO.save(bean); } public void init(Product product) { PropertyValueService propertyValueService = SpringContextUtil.getBean(PropertyValueService.class); List<Property> propertys= propertyService.listByCategory(product.getCategory()); for (Property property: propertys) { PropertyValue propertyValue = propertyValueService.getByPropertyAndProduct(product, property); if(null==propertyValue){ propertyValue = new PropertyValue(); propertyValue.setProduct(product); propertyValue.setProperty(property); propertyValueDAO.save(propertyValue); } } } @Cacheable(key="'propertyValues-one-pid-'+#p0.id+ '-ptid-' + #p1.id") public PropertyValue getByPropertyAndProduct(Product product, Property property) { return propertyValueDAO.getByPropertyAndProduct(property,product); } @Cacheable(key="'propertyValues-pid-'+ #p0.id") public List<PropertyValue> list(Product product) { return propertyValueDAO.findByProductOrderByIdDesc(product); } }
package com.how2java.tmall.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import com.how2java.tmall.dao.ReviewDAO; import com.how2java.tmall.pojo.Product; import com.how2java.tmall.pojo.Review; @Service @CacheConfig(cacheNames="reviews") public class ReviewService { @Autowired ReviewDAO reviewDAO; @Autowired ProductService productService; @CacheEvict(allEntries=true) public void add(Review review) { reviewDAO.save(review); } @Cacheable(key="'reviews-pid-'+ #p0.id") public List<Review> list(Product product){ List<Review> result = reviewDAO.findByProductOrderByIdDesc(product); return result; } @Cacheable(key="'reviews-count-pid-'+ #p0.id") public int getCount(Product product) { return reviewDAO.countByProduct(product); } }
package com.how2java.tmall.service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; 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 com.how2java.tmall.dao.UserDAO; import com.how2java.tmall.pojo.User; import com.how2java.tmall.util.Page4Navigator; import com.how2java.tmall.util.SpringContextUtil; @Service @CacheConfig(cacheNames="users") public class UserService { @Autowired UserDAO userDAO; public boolean isExist(String name) { UserService userService = SpringContextUtil.getBean(UserService.class); User user = userService.getByName(name); return null!=user; } @Cacheable(key="'users-one-name-'+ #p0") public User getByName(String name) { return userDAO.findByName(name); } @Cacheable(key="'users-one-name-'+ #p0 +'-password-'+ #p1") public User get(String name, String password) { return userDAO.getByNameAndPassword(name,password); } @Cacheable(key="'users-page-'+#p0+ '-' + #p1") public Page4Navigator<User> list(int start, int size, int navigatePages) { Sort sort = new Sort(Sort.Direction.DESC, "id"); Pageable pageable = new PageRequest(start, size,sort); Page pageFromJPA =userDAO.findAll(pageable); return new Page4Navigator<>(pageFromJPA,navigatePages); } @CacheEvict(allEntries=true) public void add(User user) { userDAO.save(user); } }
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢


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


问答区域    
2022-07-14 这里的方法调用不需要绕一绕吗
dyf137




orderServixe里的add方法被另一个方法调用了,没有走绕一绕的方式
@CacheEvict(allEntries=true)
    @Transactional(propagation= Propagation.REQUIRED,rollbackForClassName="Exception")
    public float add(Order order, List<OrderItem> ois) {
        float total = 0;
        add(order);
 
        if(false)
            throw new RuntimeException();
 
        for (OrderItem oi: ois) {
            oi.setOrder(order);
            orderItemService.update(oi);
            total+=oi.getProduct().getPromotePrice()*oi.getNumber();
        }
        return total;
    }

							


1 个答案

how2j
答案时间:2022-08-01
绕一绕的方式 是什么意思,没有get到呢



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





2021-11-19 所以,这个项目里的redis只是最基础的把所有数据都放在内存里增加查询速度吗?
你好啊007

所以,这个项目里的redis只是最基础的把所有数据都放在内存里增加查询速度吗?




2 个答案

你好啊007
答案时间:2021-12-04
啊,我在看看。 主要是问Redis的说。

how2j
答案时间:2021-12-02
哇,那么多辛苦做出来的业务功能,都被忽略掉了吗。。。



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




2021-03-10 在前面师兄弟的脚步下进步,站长康康这里;
2020-09-02 请问本项目的双写一致性是如何解决的?
2020-08-11 站长,我现在每次修改代码都要重写上传war包进行部署,有什么办法或者什么工具可以直接在部署环境对代码进行修改呢?谢谢


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

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

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

上传截图