電商Web平臺(tái)開(kāi)發(fā) 課件 4任務(wù)3 搭建配置式開(kāi)發(fā)_第1頁(yè)
電商Web平臺(tái)開(kāi)發(fā) 課件 4任務(wù)3 搭建配置式開(kāi)發(fā)_第2頁(yè)
電商Web平臺(tái)開(kāi)發(fā) 課件 4任務(wù)3 搭建配置式開(kāi)發(fā)_第3頁(yè)
電商Web平臺(tái)開(kāi)發(fā) 課件 4任務(wù)3 搭建配置式開(kāi)發(fā)_第4頁(yè)
電商Web平臺(tái)開(kāi)發(fā) 課件 4任務(wù)3 搭建配置式開(kāi)發(fā)_第5頁(yè)
已閱讀5頁(yè),還剩36頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

模塊一基礎(chǔ)技能訓(xùn)練模塊《電商web云平臺(tái)開(kāi)發(fā)》思維導(dǎo)圖搭建電商平臺(tái)Spring業(yè)務(wù)層搭建電商平臺(tái)的Web項(xiàng)目—SpringMVC展示層搭建電商平臺(tái)數(shù)據(jù)處理MyBatis項(xiàng)目1目錄CONTENTS23電商平臺(tái)SSM三層框架整合4項(xiàng)目四

電商平臺(tái)SSM三層框架整合項(xiàng)目背景

在Java互聯(lián)網(wǎng)中,SSM框架集是由Spring+SpringMVC+MyBatis(SSM)三個(gè)框架整合而成,Spring是后端組件的容器,SpringMVC提供了中央控制器和管理前端的組件,MyBatis主要用于操作數(shù)據(jù)庫(kù)。在一個(gè)項(xiàng)目中,開(kāi)發(fā)人員可以利用SSM三層框架整合出電商平臺(tái)的表現(xiàn)層、業(yè)務(wù)邏輯層和數(shù)據(jù)訪問(wèn)層。SSM框架SpringMyBatisSpringMVC本章主要圍繞電商平臺(tái)SSM三層框架整合展開(kāi),向?qū)W生介紹清楚在一個(gè)電商平臺(tái)開(kāi)發(fā)中SSM框架搭建的相關(guān)內(nèi)容,幫助學(xué)生掌握SSM三層框架的搭建技巧,故本章主要研究?jī)?nèi)容如下:研究?jī)?nèi)容認(rèn)知系統(tǒng)架構(gòu)搭建SSM開(kāi)發(fā)環(huán)境搭建配置式開(kāi)發(fā)學(xué)習(xí)目標(biāo)1.了解系統(tǒng)架構(gòu);2.認(rèn)識(shí)SSM框架;3.熟悉SSM框架的配置。知識(shí)目標(biāo)1.能夠獨(dú)立完成SSM框架的開(kāi)發(fā)環(huán)境搭建;2.能夠熟練配置SSM框架進(jìn)行項(xiàng)目開(kāi)發(fā)。技能目標(biāo)1.能夠通過(guò)三層框架整合開(kāi)發(fā)項(xiàng)目鍛煉學(xué)生的邏輯思維能力。素養(yǎng)目標(biāo)任務(wù)三搭建配置式開(kāi)發(fā)預(yù)備知識(shí)一、Web項(xiàng)目中各層說(shuō)明DAO層01實(shí)現(xiàn)數(shù)據(jù)持久層的相關(guān)操作,負(fù)責(zé)與數(shù)據(jù)庫(kù)進(jìn)行聯(lián)絡(luò)的一些任務(wù)都封裝在此。Service層02負(fù)責(zé)業(yè)務(wù)模塊的邏輯應(yīng)用設(shè)計(jì),與DAO層設(shè)計(jì)一樣,其業(yè)務(wù)實(shí)現(xiàn),具體要調(diào)用到已定義的DAO層接口。預(yù)備知識(shí)一、Web項(xiàng)目中各層說(shuō)明Controller層負(fù)責(zé)具體的業(yè)務(wù)模塊流程的控制Entity和DomainEntity是最常用的表達(dá)業(yè)務(wù)概念的實(shí)體Domain是指網(wǎng)絡(luò)中獨(dú)立運(yùn)行的單位實(shí)施準(zhǔn)備

請(qǐng)同學(xué)們使用MyEclipse開(kāi)發(fā)工具創(chuàng)建JavaWeb項(xiàng)目后,補(bǔ)充創(chuàng)建其目錄結(jié)構(gòu),然后導(dǎo)入SSM框架的所需jar包,為SSM框架的配置開(kāi)發(fā)做準(zhǔn)備。任務(wù)實(shí)施與分析步驟1:創(chuàng)建商品類別表CREATETABLEcategory_(idint(11)NOTNULLAUTO_INCREMENT,namevarchar(30),PRIMARYKEY(id))DEFAULTCHARSET=UTF8;insertintocategory_values(null,"category1");insertintocategory_values(null,"category2");insertintocategory_values(null,"category3");insertintocategory_values(null,"category4");insertintocategory_values(null,"category5");創(chuàng)建商品類別表Category向商品類別表中添加數(shù)據(jù)任務(wù)實(shí)施與分析步驟2:創(chuàng)建實(shí)體類A打開(kāi)mall項(xiàng)目B創(chuàng)建com.framework.domain包C創(chuàng)建Category實(shí)體類任務(wù)實(shí)施與分析步驟3:創(chuàng)建Mapper接口類在src目錄下創(chuàng)建com.framework.dao包創(chuàng)建CategoryMapper接口publicinterfaceCategoryMapper{ publicList<Category>list();}任務(wù)實(shí)施與分析步驟4:創(chuàng)建Mapper映射文件<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEmapperPUBLIC"-////DTDMapper3.0//EN""/dtd/mybatis-3-mapper.dtd"><mappernamespace="com.how2java.mapper.CategoryMapper"><selectid="list"resultType="Category">select*fromcategory_</select></mapper>實(shí)現(xiàn)數(shù)據(jù)庫(kù)操作的SQL語(yǔ)句任務(wù)實(shí)施與分析步驟5:創(chuàng)建service接口類12在項(xiàng)目src目錄下創(chuàng)建com.framework.service包創(chuàng)建CategoryService類publicinterfaceCategoryService{

List<Category>list();}任務(wù)實(shí)施與分析步驟6:創(chuàng)建service接口的實(shí)現(xiàn)類A創(chuàng)建com.framework.service.impl包B創(chuàng)建CategoryServiceImpl類@ServicepublicclassCategoryServiceImplimplementsCategoryService{@AutowiredCategoryMappercategoryMapper;

publicList<Category>list(){returncategoryMapper.list();}}任務(wù)實(shí)施與分析步驟7:創(chuàng)建Controller控制器類@Controller@RequestMapping("")publicclassCategoryController{@AutowiredCategoryServicecategoryService;@RequestMapping("listCategory")publicModelAndViewlistCategory(){ModelAndViewmav=newModelAndView();List<Category>cs=categoryService.list();//放入轉(zhuǎn)發(fā)參數(shù)mav.addObject("cs",cs);//放入jsp路徑mav.setViewName("listCategory");returnmav;}任務(wù)實(shí)施與分析步驟8:加載Spring配置文件0102<param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext-*.xml</param-value>指定要加載的Spring配置文件指定要加載的Spring配置文件的路徑<!--1.Spring配置文件加載--> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext-*.xml</param-value> </context-param> <listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>任務(wù)實(shí)施與分析步驟9:配置前端中央調(diào)度器實(shí)現(xiàn)認(rèn)證/授權(quán)/記錄日志、跟蹤請(qǐng)求配置前端中央調(diào)度器需要修改web.xml文件提供集中的請(qǐng)求處理機(jī)制請(qǐng)求由單一的處理程序處理任務(wù)實(shí)施與分析步驟10:配置applicationContext-core.xml在resource源文件夾下創(chuàng)建applicationContext-core.xml配置文件任務(wù)實(shí)施與分析步驟11:添加文件約束<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="/schema/beans"xmlns:xsi="/2001/XMLSchema-instance"xmlns:aop="/schema/aop"xmlns:tx="/schema/tx"xmlns:context="/schema/context"xsi:schemaLocation="/schema/beans/schema/beans/spring-beans-4.3.xsd/schema/aop/schema/aop/spring-aop-4.3.xsd/schema/tx/schema/tx/spring-tx-4.3.xsd/schema/context/schema/context/spring-context-4.3.xsd">任務(wù)實(shí)施與分析步驟12:數(shù)據(jù)源配置<context:property-placeholderlocation="classpath:/perties"/>perties為自定義創(chuàng)建在resource源文件夾下的屬性文件driverClassNameurlusernamepassword數(shù)據(jù)庫(kù)驅(qū)動(dòng)數(shù)據(jù)庫(kù)地址數(shù)據(jù)庫(kù)訪問(wèn)用戶名數(shù)據(jù)庫(kù)訪問(wèn)密碼任務(wù)實(shí)施與分析步驟13:創(chuàng)建sqlSession的工廠配置SqlSessionFactoryBean數(shù)據(jù)庫(kù)核心工廠對(duì)象、添加數(shù)據(jù)源、MyBatis配置文件以及Mapper文件路徑<beanid="sqlSessionFactory"class="org.mybatis.spring.SqlSessionFactoryBean"> <propertyname="dataSource"ref="dataSource"/> <!--添加mybatis-config配置。--> <propertyname="configLocation"value="classpath:spring-mybatis.xml"/> <!--自動(dòng)掃描mapping.xml文件--> <propertyname="mapperLocations"value="classpath:com/framework/dao/mapper/*.xml"></property></bean>任務(wù)實(shí)施與分析步驟14:掃描DAO層<beanclass="org.mybatis.spring.mapper.MapperScannerConfigurer"> <propertyname="basePackage"value="com.framework.dao"/> <propertyname="sqlSessionFactoryBeanName"value="sqlSessionFactory"></property></bean>添加SqlSessionFactoryBean數(shù)據(jù)庫(kù)核心工廠對(duì)象任務(wù)實(shí)施與分析步驟15:掃描Service層步驟16:創(chuàng)建spring-mvc.xml文件<context:component-scanbase-package="com.framework.service"/>在resource文件夾下創(chuàng)建spring-mvc.xml配置文件掃描Service業(yè)務(wù)處理層包路徑任務(wù)實(shí)施與分析步驟17:添加文件約束約束代碼<beansxmlns="/schema/beans"xmlns:xsi="/2001/XMLSchema-instance"xmlns:aop="/schema/aop"xmlns:context="/schema/context"xmlns:mvc="/schema/mvc"xsi:schemaLocation="/schema/beansttp:///schema/beans/spring-beans-4.3.xsd/schema/aop/schema/aop/spring-aop-4.3.xsd/schema/context/schema/context/spring-context-4.3.xsd/schema/mvc/schema/mvc/spring-mvc-4.3.xsd">任務(wù)實(shí)施與分析步驟18:掃描Controller包路徑使用base-package="com.framework.controller"掃描Controller路徑 <!--1.掃描controller包--> <!--掃描所有的controller但是不掃描service--> <context:component-scanbase-package="com.framework.controller"> <context:include-filtertype="annotation"expression="org.springframework.stereotype.Controller"/></context:component-scan>需要特別注意:

base-package屬性定義需要掃描的Controller包。任務(wù)實(shí)施與分析步驟19:開(kāi)啟注解驅(qū)動(dòng)<mvc:annotation-driven/>步驟20:忽略靜態(tài)資源攔截<mvc:default-servlet-handler/><mvc:resourcesmapping="/resources/**"location="/resources/"/>任務(wù)實(shí)施與分析步驟21:配置視圖解析器在spring-mvc.xml中配置視圖解析器 <beanclass="org.springframework.web.servlet.view.InternalResourceViewResolver"> <propertyname="prefix"value="/WEB-INF/templates/"/> <propertyname="suffix"value=".jsp"/>

</bean>任務(wù)實(shí)施與分析步驟2:定義接口與實(shí)體類步驟22:創(chuàng)建spring-mybatis.xml文件<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEconfigurationPUBLIC"-////DTDConfig3.0//EN""/dtd/mybatis-3-config.dtd">步驟23:添加文件約束任務(wù)實(shí)施與分析步驟24:配置日志<settings> <settingname="logImpl"value="LOG4J"/> <settingname="autoMappingBehavior"value="FULL"/></settings>步驟25:配置別名<typeAliases> <packagename="com.framework.domain"/></typeAliases>任務(wù)實(shí)施與分析步驟26:創(chuàng)建perties在resource文件夾下創(chuàng)建perties屬性文件夾在perties文件中添加數(shù)據(jù)庫(kù)相關(guān)配置jdbc.url=jdbc\:sqlserver\://localhost\:1433;DatabaseName\=malljdbc.driver=com.microsoft.sqlserver.jdbc.SQLServerDriverjdbc.username=bxdzjdbc.password=bxdz任務(wù)實(shí)施與分析步驟27:創(chuàng)建perties在resource源文件夾下創(chuàng)建屬性文件log4j.rootLogger=debug,stdoutlog4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.Target=System.outlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=[%-5p]%m%n.springframework=OFF.apache.velocity=OFF.apache.ibatis=DEBUG.framework.core.dao=DEBUG.apache.ibatis.jdbc.SimpleDataSource=DEBUG.apache.ibatis.jdbc.ScriptRunner=DEBUG.apache.ibatis.jdbc.transaction=DEBUG.apache.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUGlog4j.logger.java.sql.Connection=DEBUGlog4j.logger.java.sql=DEBUGlog4j.logger.java.sql.Statement=DEBUGlog4j.logger.java.sql.ResultSet=DEBUGlog4j.logger.java.sql.PreparedStatement=DEBUG任務(wù)實(shí)施與分析步驟28:部署項(xiàng)目項(xiàng)目部署重啟Tomcat訪問(wèn)地址觀察效果訪問(wèn)地址為:http://項(xiàng)目

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論