品優購IDEA版應該是2019年的新項目。目前只有視頻。資料其餘都仍是舊的。前端
1:瞭解電商行業特色以及理解電商的模式 2:瞭解總體品優購的架構特色 3:可以運用 Dubbo+SSM 搭建分佈式應用 4:搭建工程框架,完成品牌列表後端代碼java
品優購商城主要分爲網站前臺、網站後臺、商家後臺三類系統。mysql
主要包括網站首頁、商家首頁、商品詳情、搜索、會員中心、訂單與支付相關頁面、秒殺頻道等。 git
運營該電商平臺的運營人員的管理後臺。 主要包括商家審覈、品牌管理、規格管理、模板管理、商品分類管理、商品審覈、廣告類型管理、廣告管理、訂單查詢、商家結算等。github
加入了該電商平臺的商家進行管理的後臺,主要功能是對商品的管理以及訂單查詢統計、資金結算等功能。web
品優購採用當前流行的先後端分離架構。後端框架採用 Spring + Spring MVC + Mybatis +Dubbo。前端採用 angularJS + Bootstrap。redis
> DUBBO 是一個分佈式服務框架,致力於提供高性能和透明化的 RPC 遠程服 務調用方案,是阿里巴巴 > SOA(Service-Oriented Architecture,SOA,面向服務架構) 服務化治理方案的核心框架,天天爲 > 2,000+個服務提供 3,000,000,000+次訪問量 > 支持,並被普遍應用於阿里巴巴集團的各成員站點。官網地址:http://dubbo.io/算法
節點角色說明: | 英文名 | 節點角色說明 | |--|--| | Provider |暴露服務的服務提供方。 | | Consumer|調用遠程服務的服務消費方。 | | Registry|服務註冊與發現的註冊中心。 | | Monitor|統計服務的調用次調和調用時間的監控中心。 | | Container|服務運行容器。 |spring
調用關係說明:sql
> 【軟負載均衡】軟件負載均衡則是經過在服務器上安裝的特定的負載均衡軟件或是自帶負載均衡模塊完成對請求的分配派發。如:輪詢法、隨機法、源地址哈希 法、最小鏈接數法等。在消費方中聲明服務的時候能夠指定負載均衡的策略, dubbo 在返回的服務地址列表中使用負載均衡策略選擇一個服務地址;默認是使 用隨機法。
官方推薦使用 zookeeper 註冊中心。註冊中心負責服務地址的註冊與查找,至關於目錄服務,服務提供者和消費者只在啓動時與註冊中心交互,註冊中心不轉發請求,壓力較小。
zookeeper 是 Apacahe Hadoop 的子項目,是一個樹型的目錄服務,支持變動推送,適合做爲 Dubbo 服務的註冊中心,工業強度較高,可用於生產環境。
zooKeeper 用來作 dubbo 的註冊中心,也即哪個服務由哪一臺機器來提供 必需讓調用者知道,簡單來講就是 ip 地址和服務名稱的對應關係。
導入的虛擬機必須設置 ip 爲 192.168.25.168 纔可使用 FastDFS(後面的課程會 用);若是虛擬機不是 25 網段,須要手動設置網段,設置方式以下圖:
> 由於除了只有視頻是新的,軟件資源其實都仍是舊的,因此實際上是須要使用25網段
找到下發的虛擬機文件夾「pinyougou」;導入 VMWare 內,步驟以下: 若是出現彈出框;那麼選擇 我已移動該虛擬機
上述安裝的 CentOS7 64 位系統; 賬號:root,密碼:itcast
【注意】若是啓動後沒法在 windows 中使用工具鏈接(systemctl start network.service 命令能夠查看狀態);那麼能夠在 centos 中重啓網絡;輸入以下 命令: systemctl stop NetworkManager systemctl restart network.service
進入桌面後,右擊進入terminal輸入ifconfig,查看ip
ifconfig
將zookeeper-3.4.6.tar.gz上傳到服務器的/root/目錄下 解壓
tar -zxvf zookeeper-3.4.6.tar.gz
進入zookeeper-3.4.6目錄。建立data文件夾 進入conf(配置)文件夾,重命名zoo_sample.cfg爲zoo.cfg。修改zoo.cfg文件。 進入bin文件夾,啓動zookeeper
在開發時,須要知道註冊中心都註冊了哪些服務,以便咱們開發和測試。能夠經過部署一個監控中心來實現。其實監控中心就是一個 web 應用,部署到tomcat 便可。
上傳tomcat與dubbo-admin到服務器
或者
開發完成後的工程結構以下:
| 模塊名 |工程說明 | |--|--| |pinyougou-parent | 聚合父工程 | |pinyougou-pojo | 通用實體類 | |pinyougou-dao | 通用實體類 | |pinyougou-xxx | 業務服務層工程 | |pinyougou-xxx-interface | 業務服務層接口 | |pinyougou-xxx-service | 業務服務層實現(web 工程) | |pinyougou-xxx-web | 展示(控制)層工程(web 工程) |
在導入的虛擬機裏面已經有使用 mysql 5.7 的數據庫名稱爲:pinyougoudb, mysql5.7 的用戶名和密碼都爲:root。 另外;也能夠自行建立數據庫,將「資料/database/pinyougoudb.sql」導入。
品優購聚合父工程;包括後續開發的全部品優購聚合子工程。主要功能是進行依賴、插件統一管理。
> 後續的文中出現依賴表示修改當前項目的 pom.xml 文件
<!--?xml version="1.0" encoding="UTF-8"?--> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupid>com.pinyougou</groupid> <artifactid>pinyougou</artifactid> <packaging>pom</packaging> <version>1.0-SNAPSHOT</version> <!-- 集中定義依賴版本號 --> <properties> <junit.version>4.12</junit.version> <spring.version>4.3.10.RELEASE</spring.version> <spring.security.version>4.2.3.RELEASE</spring.security.version> <mybatis.version>3.4.5</mybatis.version> <mybatis.spring.version>1.3.1</mybatis.spring.version> <mysql.version>5.1.32</mysql.version> <druid.version>1.1.5</druid.version> <pagehelper.version>5.1.2</pagehelper.version> <mapper.version>3.5.0</mapper.version> <dubbo.version>2.6.0</dubbo.version> <slf4j.version>1.7.12</slf4j.version> <javax.persistence.version>1.0</javax.persistence.version> <fastjson.version>1.2.44</fastjson.version> <zookeeper.version>3.4.9</zookeeper.version> <zkclient.version>0.1</zkclient.version> <jedis.version>2.9.0</jedis.version> <spring.data.redis.version>1.8.9.RELEASE</spring.data.redis.version> <servlet.api.version>2.5</servlet.api.version> <commons.fileupload.version>1.3.1</commons.fileupload.version> <fastdfs.client.version>1.25</fastdfs.client.version> <freemarker.version>2.3.23</freemarker.version> <activemq.version>5.14.3</activemq.version> <cas.client.core.version>3.4.1</cas.client.core.version> <spring.data.solr.version>1.5.5.RELEASE</spring.data.solr.version> <httpclient.version>4.5.3</httpclient.version> <wxpay.sdk.version>0.0.3</wxpay.sdk.version> <httpcore.version>4.4.8</httpcore.version> <javassist.version>3.12.1.GA</javassist.version> <commons.codec.version>1.11</commons.codec.version> <dom4j.version>1.6.1</dom4j.version> <xml.apis.version>2.0.2</xml.apis.version> <kaptcha.version>2.3.2</kaptcha.version> </properties> <dependencymanagement> <dependencies> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <version>${junit.version}</version> </dependency> <!-- Spring --> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-beans</artifactid> <version>${spring.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-context</artifactid> <version>${spring.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-web</artifactid> <version>${spring.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-aspects</artifactid> <version>${spring.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-jdbc</artifactid> <version>${spring.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-webmvc</artifactid> <version>${spring.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-jms</artifactid> <version>${spring.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-context-support</artifactid> <version>${spring.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-test</artifactid> <version>${spring.version}</version> </dependency> <!-- Mybatis --> <dependency> <groupid>org.mybatis</groupid> <artifactid>mybatis</artifactid> <version>${mybatis.version}</version> </dependency> <dependency> <groupid>org.mybatis</groupid> <artifactid>mybatis-spring</artifactid> <version>${mybatis.spring.version}</version> </dependency> <!-- 日誌 --> <dependency> <groupid>org.slf4j</groupid> <artifactid>slf4j-log4j12</artifactid> <version>${slf4j.version}</version> </dependency> <!-- dubbo相關 --> <dependency> <groupid>com.alibaba</groupid> <artifactid>dubbo</artifactid> <version>${dubbo.version}</version> </dependency> <dependency> <groupid>org.apache.zookeeper</groupid> <artifactid>zookeeper</artifactid> <version>${zookeeper.version}</version> </dependency> <dependency> <groupid>com.github.sgroschupf</groupid> <artifactid>zkclient</artifactid> <version>${zkclient.version}</version> </dependency> <!-- json的解析 --> <dependency> <groupid>com.alibaba</groupid> <artifactid>fastjson</artifactid> <version>${fastjson.version}</version> </dependency> <dependency> <groupid>javax.servlet</groupid> <artifactid>servlet-api</artifactid> <version>${servlet.api.version}</version> <scope>provided</scope> </dependency> <!-- mybaits分頁助手 --> <dependency> <groupid>com.github.pagehelper</groupid> <artifactid>pagehelper</artifactid> <version>${pagehelper.version}</version> </dependency> <!-- 通用 Mapper --> <dependency> <groupid>tk.mybatis</groupid> <artifactid>mapper</artifactid> <version>${mapper.version}</version> </dependency> <!-- MySql --> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>${mysql.version}</version> </dependency> <!-- 鏈接池 --> <dependency> <groupid>com.alibaba</groupid> <artifactid>druid</artifactid> <version>${druid.version}</version> </dependency> <!-- jpa 註解 --> <dependency> <groupid>javax.persistence</groupid> <artifactid>persistence-api</artifactid> <version>${javax.persistence.version}</version> </dependency> <!-- redis緩存 --> <dependency> <groupid>redis.clients</groupid> <artifactid>jedis</artifactid> <version>${jedis.version}</version> </dependency> <dependency> <groupid>org.springframework.data</groupid> <artifactid>spring-data-redis</artifactid> <version>${spring.data.redis.version}</version> </dependency> <!-- 文件上傳組件 --> <dependency> <groupid>commons-fileupload</groupid> <artifactid>commons-fileupload</artifactid> <version>${commons.fileupload.version}</version> </dependency> <!--fastDFS客戶端工具類包 --> <dependency> <groupid>fastdfs_client</groupid> <artifactid>fastdfs_client</artifactid> <version>${fastdfs.client.version}</version> </dependency> <!--freemarker--> <dependency> <groupid>org.freemarker</groupid> <artifactid>freemarker</artifactid> <version>${freemarker.version}</version> </dependency> <!-- ActiveMQ --> <dependency> <groupid>org.apache.activemq</groupid> <artifactid>activemq-client</artifactid> <version>${activemq.version}</version> </dependency> <!-- 身份驗證 --> <dependency> <groupid>org.springframework.security</groupid> <artifactid>spring-security-web</artifactid> <version>${spring.security.version}</version> </dependency> <dependency> <groupid>org.springframework.security</groupid> <artifactid>spring-security-config</artifactid> <version>${spring.security.version}</version> </dependency> <!-- cas --> <dependency> <groupid>org.springframework.security</groupid> <artifactid>spring-security-cas</artifactid> <version>${spring.security.version}</version> </dependency> <dependency> <groupid>org.jasig.cas.client</groupid> <artifactid>cas-client-core</artifactid> <version>${cas.client.core.version}</version> <!-- 排除 log4j包衝突 --> <exclusions> <exclusion> <groupid>org.slf4j</groupid> <artifactid>log4j-over-slf4j</artifactid> </exclusion> </exclusions> </dependency> <!-- solr相關 --> <dependency> <groupid>org.springframework.data</groupid> <artifactid>spring-data-solr</artifactid> <version>${spring.data.solr.version}</version> </dependency> <dependency> <groupid>org.apache.httpcomponents</groupid> <artifactid>httpclient</artifactid> <version>${httpclient.version}</version> </dependency> <!-- 微信支付 sdk --> <dependency> <groupid>com.github.wxpay</groupid> <artifactid>wxpay-sdk</artifactid> <version>${wxpay.sdk.version}</version> </dependency> <!-- 驗證碼工具類包 --> <dependency> <groupid>com.github.penggle</groupid> <artifactid>kaptcha</artifactid> <version>${kaptcha.version}</version> <exclusions> <exclusion> <groupid>javax.servlet</groupid> <artifactid>javax.servlet-api</artifactid> </exclusion> </exclusions> </dependency> <!-- 加密解密 --> <dependency> <groupid>commons-codec</groupid> <artifactid>commons-codec</artifactid> <version>${commons.codec.version}</version> </dependency> <dependency> <groupid>javassist</groupid> <artifactid>javassist</artifactid> <version>${javassist.version}</version> </dependency> <dependency> <groupid>dom4j</groupid> <artifactid>dom4j</artifactid> <version>${dom4j.version}</version> </dependency> <dependency> <groupid>xml-apis</groupid> <artifactid>xml-apis</artifactid> <version>${xml.apis.version}</version> </dependency> </dependencies> </dependencymanagement> <build> <plugins> <!-- java編譯插件 --> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <version>3.6.0</version> <configuration> <source>1.8 <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> <pluginmanagement> <plugins> <!-- tomcat插件 --> <plugin> <groupid>org.apache.tomcat.maven</groupid> <artifactid>tomcat7-maven-plugin</artifactid> <version>2.2</version> </plugin> </plugins> </pluginmanagement> </build> </project>
通用工具類工程;放置其它工程常用的工具類或者組件。
<!--?xml version="1.0" encoding="UTF-8"?--> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactid>pinyougou</artifactid> <groupid>com.pinyougou</groupid> <version>1.0-SNAPSHOT</version> </parent> <modelversion>4.0.0</modelversion> <artifactid>pinyougou-common</artifactid> </project>
實體類工程;統一放置品優購的全部數據庫實體類或者其它領域模型。
建立 pinyougou 的子模塊工程,與 pinyougou-common 的建立方式相似;後面的如果pinyougou 的子模塊工程的建立也都如此;再也不每一步都截圖了。
<!--?xml version="1.0" encoding="UTF-8"?--> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactid>pinyougou</artifactid> <groupid>com.pinyougou</groupid> <version>1.0-SNAPSHOT</version> </parent> <modelversion>4.0.0</modelversion> <artifactid>pinyougou-pojo</artifactid> <dependencies> <!-- jpa 註解 --> <dependency> <groupid>javax.persistence</groupid> <artifactid>persistence-api</artifactid> </dependency> <dependency> <groupid>org.springframework.data</groupid> <artifactid>spring-data-solr</artifactid> </dependency> </dependencies> </project>
數據庫通用訪問層工程;放置 Mybatis 中對應於數據庫操做的全部 Mapper 接口類。
<!--?xml version="1.0" encoding="UTF-8"?--> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactid>pinyougou</artifactid> <groupid>com.pinyougou</groupid> <version>1.0-SNAPSHOT</version> </parent> <modelversion>4.0.0</modelversion> <artifactid>pinyougou-dao</artifactid> <dependencies> <dependency> <groupid>com.pinyougou</groupid> <artifactid>pinyougou-pojo</artifactid> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-beans</artifactid> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-jdbc</artifactid> </dependency> <!-- Mybatis --> <dependency> <groupid>org.mybatis</groupid> <artifactid>mybatis</artifactid> </dependency> <dependency> <groupid>org.mybatis</groupid> <artifactid>mybatis-spring</artifactid> </dependency> <!-- mybaits分頁助手 --> <dependency> <groupid>com.github.pagehelper</groupid> <artifactid>pagehelper</artifactid> </dependency> <!-- 通用 Mapper --> <dependency> <groupid>tk.mybatis</groupid> <artifactid>mapper</artifactid> </dependency> <!-- MySql --> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> </dependency> <!-- 鏈接池 --> <dependency> <groupid>com.alibaba</groupid> <artifactid>druid</artifactid> </dependency> <!-- 日誌 --> <dependency> <groupid>org.slf4j</groupid> <artifactid>slf4j-log4j12</artifactid> </dependency> </dependencies> </project>
商家商品服務工程;該工程主要是對應於商品、商家、品牌、規格、商品分類等 的服務提供,由 pinyougou-sellergoods-interface 和 pinyougou-sellergoods-service構成。
無需改動。
注意這個工程是 pinyougou-sellergoods 的聚合子工程。
<!--?xml version="1.0" encoding="UTF-8"?--> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactid>pinyougou-sellergoods</artifactid> <groupid>com.pinyougou</groupid> <version>1.0-SNAPSHOT</version> </parent> <modelversion>4.0.0</modelversion> <artifactid>pinyougou-sellergoods-interface</artifactid> <dependencies> <dependency> <groupid>com.pinyougou</groupid> <artifactid>pinyougou-pojo</artifactid> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> </project>
注意這個工程是 pinyougou-sellergoods 的聚合子工程。 安裝插件JBLJavaToWeb
<!--?xml version="1.0" encoding="UTF-8"?--> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactid>pinyougou-sellergoods</artifactid> <groupid>com.pinyougou</groupid> <version>1.0-SNAPSHOT</version> </parent> <modelversion>4.0.0</modelversion> <artifactid>pinyougou-sellergoods-service</artifactid> <packaging>war</packaging> <dependencies> <dependency> <groupid>com.pinyougou</groupid> <artifactid>pinyougou-sellergoods-interface</artifactid> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupid>com.pinyougou</groupid> <artifactid>pinyougou-dao</artifactid> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-beans</artifactid> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-context</artifactid> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-web</artifactid> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-aspects</artifactid> </dependency> <!-- dubbo相關 --> <dependency> <groupid>com.alibaba</groupid> <artifactid>dubbo</artifactid> </dependency> <dependency> <groupid>org.apache.zookeeper</groupid> <artifactid>zookeeper</artifactid> </dependency> <dependency> <groupid>com.github.sgroschupf</groupid> <artifactid>zkclient</artifactid> </dependency> <dependency> <groupid>com.alibaba</groupid> <artifactid>fastjson</artifactid> </dependency> <dependency> <groupid>com.pinyougou</groupid> <artifactid>pinyougou-common</artifactid> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> <build> <plugins> <!-- tomcat插件 --> <plugin> <groupid>org.apache.tomcat.maven</groupid> <artifactid>tomcat7-maven-plugin</artifactid> <configuration> <path>/</path> <port>9000</port> </configuration> </plugin> </plugins> </build> </project>
<!--?xml version="1.0" encoding="UTF-8"?--> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactid>pinyougou</artifactid> <groupid>com.pinyougou</groupid> <version>1.0-SNAPSHOT</version> </parent> <modelversion>4.0.0</modelversion> <artifactid>pinyougou-manage-web</artifactid> <packaging>war</packaging> <dependencies> <dependency> <groupid>com.pinyougou</groupid> <artifactid>pinyougou-sellergoods-interface</artifactid> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-webmvc</artifactid> </dependency> <dependency> <groupid>org.slf4j</groupid> <artifactid>slf4j-log4j12</artifactid> </dependency> <!-- dubbo相關 --> <dependency> <groupid>com.alibaba</groupid> <artifactid>dubbo</artifactid> </dependency> <dependency> <groupid>org.apache.zookeeper</groupid> <artifactid>zookeeper</artifactid> </dependency> <dependency> <groupid>com.github.sgroschupf</groupid> <artifactid>zkclient</artifactid> </dependency> <!-- json的解析 --> <dependency> <groupid>com.alibaba</groupid> <artifactid>fastjson</artifactid> </dependency> <dependency> <groupid>javax.servlet</groupid> <artifactid>servlet-api</artifactid> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <!-- tomcat插件 --> <plugin> <groupid>org.apache.tomcat.maven</groupid> <artifactid>tomcat7-maven-plugin</artifactid> <configuration> <path>/</path> <port>9100</port> </configuration> </plugin> </plugins> </build> </project>
添加 pinyougou\pinyougou-dao\src\main\resources\spring\applicationContext-dao.xml 內容以下:
<!--?xml version="1.0" encoding="UTF-8"?--> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns="http://www.springframework.org/schema/beans" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 加載配置文件 --> <context:property-placeholder location="classpath*:properties/*.properties" /> <!-- 數據庫鏈接池 --> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close"> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="driverClassName" value="${jdbc.driver}" /> <property name="maxActive" value="10" /> <property name="minIdle" value="5" /> </bean> <!-- 配置 sqlSessionFactory --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 數據源 --> <property name="dataSource" ref="dataSource" /> <!-- mybatis總配置文件 --> <property name="configLocation" value="classpath:mybatis/mybatis-config.xml" /> <!-- 配置實體類別名 --> <property name="typeAliasesPackage" value="com.pinyougou.pojo" /> <!--配置掃描xml文件--> <property name="mapperLocations" value="classpath:com/pinyougou/mapper/*.xml" /> </bean> <!-- 掃描 mapper --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.pinyougou.mapper" /> </bean> </beans>
添加 pinyougou\pinyougou-dao\src\main\resources\mybatis\mybatis-config.xml 內容以下:
<!--?xml version="1.0" encoding="UTF-8" ?--> <configuration> <settings> <!-- 開啓駝峯規則自動映射字段屬性值;如字段爲 user_name的能夠映射到 userName屬性中 --> <setting name="mapUnderscoreToCamelCase" value="true" /> </settings> </configuration>
添加 pinyougou\pinyougou-dao\src\main\resources\properties\db.properties 內容以下:
jdbc.driver=com.mysql.jdbc.Driver #下面的按照本身實際的填寫。若是鏈接服務器的mysql,就填寫你服務器的ip。若是鏈接的是本地的mysql,就填寫localhost jdbc.url=jdbc:mysql://192.168.25.128:3306/pinyougoudb?useUnicode=true&characterEncoding=utf8&autoReconnect=true jdbc.username=root jdbc.password=root
添加 pinyougou\pinyougou-dao\src\main\resources\log4j.properties 內容以下:
log4j.rootLogger=DEBUG,stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c]-[%p] %m%n
添加 pinyougou-sellergoods-service\src\main\resources\spring\applicationContext service.xml 內容以下:
<!--?xml version="1.0" encoding="UTF-8"?--> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns="http://www.springframework.org/schema/beans" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <dubbo:protocol name="dubbo" port="20881" /> <dubbo:application name="pinyougou-sellergoods-service" /> <!--根據服務器實際ip填寫--> <dubbo:registry address="zookeeper://192.168.25.128:2181" /> <dubbo:annotation package="com.pinyougou.sellergoods.service.impl" /> </beans>
修改pinyougou-sellergoods-service\src\main\webapp\WEB-INF\web.xml內容以下:
<!--?xml version="1.0" encoding="UTF-8"?--> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:spring/applicationContext*.xml</param-value> </context-param> </web-app>
添加 pinyougou\pinyougou-manage-web\src\main\resources\spring\springmvc.xml 內容以下:
<!--?xml version="1.0" encoding="UTF-8"?--> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns="http://www.springframework.org/schema/beans" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <mvc:annotation-driven> <mvc:message-converters register-defaults="true"> <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> <property name="supportedMediaTypes" value="application/json" /> </bean> </mvc:message-converters> </mvc:annotation-driven> <!-- 引用 dubbo 服務 --> <dubbo:application name="pinyougou-manage-web" /> <!-- 根據實際ip填寫 --> <dubbo:registry address="zookeeper://192.168.25.128:2181" /> <dubbo:annotation package="com.pinyougou.manage.controller" /> </beans>
添加 pinyougou\pinyougou-manage-web\src\main\resources\log4j.properties 內容以下:
log4j.rootLogger=DEBUG,stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c]-[%p] %m%n
修改 pinyougou\pinyougou-manage-web\src\main\webapp\WEB-INF\web.xml 內容以下:
<!--?xml version="1.0" encoding="UTF-8"?--> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <!-- 解決 post亂碼 --> <filter> <filter-name>CharacterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter </filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 指定加載的配置文件 ,經過參數 contextConfigLocation加載 --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/springmvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> </web-app>
6.4.4. 引入品優購實體類 在 pinyougou-pojo 工程建立 com.pinyougou.pojo 包;而後將「資料/pojo」下的全部 實體類複製到上述建立的包中。
在瀏覽器上訪問:http://localhost:9100/brand/findAll.do 把品牌數據(json 格式字 符串)加載並顯示。
添加 pinyougou-dao\src\main\java\com\pinyougou\mapper\BrandMapper.java 內容以下:
package com.pinyougou.mapper; import com.pinyougou.pojo.TbBrand; import java.util.List; public interface BrandMapper { List<tbbrand> queryAll(); }
添加 pinyougou-dao\src\main\resources\com\pinyougou\mapper\BrandMapper.xml 內容以下:
<!--?xml version="1.0" encoding="UTF-8"?--> <mapper namespace="com.pinyougou.mapper.BrandMapper"> <select id="queryAll" resulttype="com.pinyougou.pojo.TbBrand"> SELECT * FROM tb_brand </select> </mapper>
添加 pinyougou-sellergoods\pinyougou-sellergoods interface\src\main\java\com\pinyougou\sellergoods\service\BrandService.java 內容以下:
package com.pinyougou.sellergoods.service; import com.pinyougou.pojo.TbBrand; import java.util.List; public interface BrandService { public List<tbbrand> queryAll(); }
添加 pinyougou-sellergoods\pinyougou-sellergoods service\src\main\java\com\pinyougou\sellergoods\service\impl\BrandServiceImpl.ja va 內容以下:
package com.pinyougou.sellergoods.service.impl; import java.util.List; import com.pinyougou.mapper.BrandMapper; import com.pinyougou.sellergoods.service.BrandService; import org.springframework.beans.factory.annotation.Autowired; import com.alibaba.dubbo.config.annotation.Service; import com.pinyougou.pojo.TbBrand; /** * 注意:該Service註解是alibaba的,不是spring的 */ @Service(interfaceClass = BrandService.class) public class BrandServiceImpl implements BrandService { @Autowired private BrandMapper brandMapper; @Override public List<tbbrand> queryAll() { return brandMapper.queryAll(); } }
添加 pinyougou-manage web\src\main\java\com\pinyougou\manage\controller\BrandController.java 內容以下:
package com.pinyougou.manage.controller; import java.util.List; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.alibaba.dubbo.config.annotation.Reference; import com.pinyougou.pojo.TbBrand; import com.pinyougou.sellergoods.service.BrandService; @RestController @RequestMapping("/brand") public class BrandController { @Reference private BrandService brandService; @RequestMapping("/findAll") public List<tbbrand> findAll(){ return brandService.queryAll(); } }
點擊 IDEA 最右邊的「Maven Projects」
這個啓動與 pinyougou-sellergoods-service 的啓動配置是同樣的;不在贅述圖。 7.6. 測試 打開 chrome 瀏覽器;輸入:http://localhost:9100/brand/findAll.do
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.RuntimeException: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.pinyougou.mapper.BrandMapper.queryAll org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.pinyougou.mapper.BrandMapper.queryAll
在 IDEA 中檢查 resources 文件夾中 com.pinyougou.mapper 是否是已經變成了 一個目錄;真正的是三級目錄,只是在 IDEA 上看不太出區別。請建立的時候 建立 package 方 式 創 建 則 不 會 出 現 了 ; 不 管 如 何 請 保 證 resources/com/pinyougou/mapper 目錄的存在
> 以上爲第一天內容,視頻參考Java 品優購互聯網商城 項目實戰(基於IDEA)新版。由於第一天是沒有視頻的,是基於這份pdf講義實現的。然而這份pdf講義也有不少錯誤,有的是由於資源是舊的,不兼容,還有的是直接是裏面代碼的錯誤致使的bug。以上我博客的內容基本是花了時間排除了錯誤後的實現。因此有些地方會與講義不一樣。 第一天內容我寫了思惟導圖,打開有點慢。 博客內容中,若是我有哪些沒有講清楚或者實現中遇到了哪些問題,請在評論中留言,我看到會盡快回復的,或者其餘小夥伴看到也會幫忙解決的。 第一天須要使用的資料hirr,或者不失效的 </tbbrand></tbbrand></tbbrand></tbbrand>