今日任務
完成分類模組的功能
#完成商品模組的功能
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();</category>
2.非同步載入分類:
$(function() { $.post("/store_v2.0/CategoryServlet", {"method" : "findAll"}, function(data) { $.each(data, function(i, n) { $("#menu").append("
3.使用快取技術:對程式進行最佳化.
* 快取:其實就是記憶體中的一塊空間.可以使用快取將資料來源中的資料拿到,存入記憶體.後期取得資料的話從快取取得.
* Memcache :
* EHCache :是Hibernate常用的二級快取的外掛程式.
* Redis :
* 使用ehcache:
:
* 使用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;
}</category></category></category>
1.2 前台頁面上的商品顯示:
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(); }</product></product># #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.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
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3漢化版
中文版,非常好用

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

記事本++7.3.1
好用且免費的程式碼編輯器

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。