今日任务
完成分类模块的功能
完成商品模块的功能
1.1 分类模块的功能:
1.1.1 查询分类的功能:
1.1.2 查询分类的代码实现:
1.1.2.1 创建表:
CREATE TABLE `category` ( `cid` varchar(32) NOT NULL, `cname` varchar(20) DEFAULT NULL, PRIMARY KEY (`cid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1.1.2.2 功能实现:
1.直接查询所有分类:
CategoryDao categoryDao = new CategoryDaoImpl(); List<Category> list = categoryDao.findAll();
2.异步加载分类:
$(function() { $.post("/store_v2.0/CategoryServlet", {"method" : "findAll"}, function(data) { $.each(data, function(i, n) { $("#menu").append("<li><a href='#'>" + n.cname + "</a></li>"); }); }, "json"); });
3.使用缓存技术:对程序进行优化.
* 缓存:其实就是内存中的一块空间.可以使用缓存将数据源中的数据拿到,存入到内存中.后期获得数据的话 从缓存中进行获得.
* Memcache :
* EHCache :是Hibernate常使用的二级缓存的插件.
* Redis :
* 使用ehcache:
* 引入jar包:
* 引入配置文件:
// 业务层查询所有分类的方法:public List<Category> findAll() throws SQLException {/* * CategoryDao categoryDao = new CategoryDaoImpl(); return * categoryDao.findAll(); *//** * 从缓存中查询数据: * * 有数据,直接将缓存的数据返回. * * 如果没有,查询数据库,数据存入到缓存中. */List<Category> list = null; // 从缓存中进行查询:CacheManager cacheManager = CacheManager .create(CategoryServiceImpl.class.getClassLoader().getResourceAsStream("ehcache.xml")); Cache cache = cacheManager.getCache("categoryCache"); Element element = cache.get("list");if(element != null){// 缓存中有数据:System.out.println("缓存中有数据..."); list = (List<Category>) element.getObjectValue(); }else{// 缓存中没有数据:System.out.println("缓存中没有数据..."); CategoryDao categoryDao = new CategoryDaoImpl(); list = categoryDao.findAll(); Element e = new Element("list", list);// cache.cache.put(e); }return list; }
1.2 前台页面上的商品显示:
1.2.1 商品显示准备工作:
1.2.1.1 创建表:
CREATE TABLE `product` ( `pid` varchar(32) NOT NULL, `pname` varchar(50) DEFAULT NULL, `market_price` double DEFAULT NULL, `shop_price` double DEFAULT NULL, `pimage` varchar(200) DEFAULT NULL, `pdate` datetime DEFAULT NULL, `is_hot` int(11) DEFAULT NULL,-- 1:热门 `pdesc` varchar(255) DEFAULT NULL, `pflag` int(11) DEFAULT NULL,-- 1:下架 `cid` varchar(32) DEFAULT NULL, PRIMARY KEY (`pid`), KEY `sfk_0001` (`cid`), CONSTRAINT `sfk_0001` FOREIGN KEY (`cid`) REFERENCES `category` (`cid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1.2.1.2 创建类:
1.2.2 首页上的热门商品的显示和最新商品的显示
ProductService productService = new ProductServiceImpl();try {// 查询热门商品:List<Product> hotList = productService.findByHot();// 查询最新商品:List<Product> newList = productService.findByNew(); req.setAttribute("hotList",hotList); req.setAttribute("newList",newList); } catch (SQLException e) { e.printStackTrace();throw new RuntimeException(); }
1.2.3 商品详情的显示
public String findById(HttpServletRequest req,HttpServletResponse resp){// 接收参数:String pid = req.getParameter("pid");// 调用业务层:ProductService productService = new ProductServiceImpl();try { Product product = productService.findById(pid); req.setAttribute("product",product); } catch (SQLException e) { e.printStackTrace();throw new RuntimeException(); }// 页面跳转return "/jsp/product_info.jsp"; }
1.2.4 显示某个分类下的商品:
1.在首页上点击分类的链接:
2.提交到Servlet:
* 接收参数:分类的ID
* 当前页面:当前页数1
* 调用业务层:
* 封装PageBean:
* 页面跳转:
以上是JAVA商城实战之异步加载分类、Redis缓存分类和显示商品的详细内容。更多信息请关注PHP中文网其他相关文章!

JVM'SperformanceIsCompetitiveWithOtherRuntimes,operingabalanceOfspeed,安全性和生产性。1)JVMUSESJITCOMPILATIONFORDYNAMICOPTIMIZAIZATIONS.2)c提供NativePernativePerformanceButlanceButlactsjvm'ssafetyFeatures.3)

JavaachievesPlatFormIndependencEthroughTheJavavIrtualMachine(JVM),允许CodeTorunonAnyPlatFormWithAjvm.1)codeisscompiledIntobytecode,notmachine-specificodificcode.2)bytecodeisisteredbytheybytheybytheybythejvm,enablingcross-platerssectectectectectross-eenablingcrossectectectectectection.2)

TheJVMisanabstractcomputingmachinecrucialforrunningJavaprogramsduetoitsplatform-independentarchitecture.Itincludes:1)ClassLoaderforloadingclasses,2)RuntimeDataAreafordatastorage,3)ExecutionEnginewithInterpreter,JITCompiler,andGarbageCollectorforbytec

JVMhasacloserelationshipwiththeOSasittranslatesJavabytecodeintomachine-specificinstructions,managesmemory,andhandlesgarbagecollection.ThisrelationshipallowsJavatorunonvariousOSenvironments,butitalsopresentschallengeslikedifferentJVMbehaviorsandOS-spe

Java实现“一次编写,到处运行”通过编译成字节码并在Java虚拟机(JVM)上运行。1)编写Java代码并编译成字节码。2)字节码在任何安装了JVM的平台上运行。3)使用Java原生接口(JNI)处理平台特定功能。尽管存在挑战,如JVM一致性和平台特定库的使用,但WORA大大提高了开发效率和部署灵活性。

JavaachievesPlatFormIndependencethroughTheJavavIrtualMachine(JVM),允许Codetorunondifferentoperatingsystemsswithoutmodification.thejvmcompilesjavacodeintoplatform-interploplatform-interpectentbybyteentbytybyteentbybytecode,whatittheninternterninterpretsandectectececutesoneonthepecificos,atrafficteyos,Afferctinginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginging

JavaispoperfulduetoitsplatFormitiondence,对象与偏见,RichstandardLibrary,PerformanceCapabilities和StrongsecurityFeatures.1)Platform-dimplighandependectionceallowsenceallowsenceallowsenceallowsencationSapplicationStornanyDevicesupportingJava.2)

Java的顶级功能包括:1)面向对象编程,支持多态性,提升代码的灵活性和可维护性;2)异常处理机制,通过try-catch-finally块提高代码的鲁棒性;3)垃圾回收,简化内存管理;4)泛型,增强类型安全性;5)ambda表达式和函数式编程,使代码更简洁和表达性强;6)丰富的标准库,提供优化过的数据结构和算法。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

禅工作室 13.0.1
功能强大的PHP集成开发环境

Atom编辑器mac版下载
最流行的的开源编辑器

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)