主頁 > 軟體設計 > javaweb-青橙專案-1-76

javaweb-青橙專案-1-76

2021-04-19 11:09:35 軟體設計

文章目錄

  • 1.專案預計
    • 1.1小專案特點
    • 1.2大專案特點
    • 1.3 主要電商模式
  • 2. 青橙-需求分析與系統設計
    • 2.1 需求分析
    • 2.2 系統設計
      • 2.2.1 資料庫分庫設計
      • 2.2.3 系統架構圖
  • 3. 通用mapper
    • 3.1 通用mapper簡介
    • 3.2 通用mapper快速入門
      • 3.2.1 通用mapper與Spring集成
      • 3.2.2 物體類映射
      • 3.2.3 創建Mapper介面
    • 4.3 工程搭建
      • 4.3.1 父工程與公共模塊
      • 4.3.2 服務層模塊(商品)
      • 4.3.3 web層(管理后臺)
  • 5. 青橙管理后臺-品牌管理后端
    • 5.1 需求分析
    • 5.2 表結構分析
    • 5.3 代碼實作
      • 5.3.1 品牌串列
      • 測驗
      • 5.3.2 品牌分頁串列
      • 5.3.3 品牌條件查詢
      • 5.3.4 品牌條件+分頁查詢
      • 5.3.5 根據ID查詢品牌
      • 5.3.6 品牌新增
      • 5.3.7 品牌修改
      • 5.3.8 品牌洗掉
  • 6. 公共例外處理

1.專案預計

序列1-地址:https://github.com/Jonekaka/javaweb-qingcheng-1-76/tree/master/qingchengcode/qingchengcode

1.1小專案特點

對于一些小專案ssm就夠了,但是對于高并發的大專案
需要更多新技術的融合與賦能

1.2大專案特點

技術新,技術范圍廣-技術
分布式、集群、高并發、負載均衡、高可用-設備壓力分擔
海量資料-資料
業務復雜-業務
系統安全-安全
將多個小設備虛擬為一個超算

1.3 主要電商模式

B2B ( Business to Business)是指進行電子商務交易的供需雙方都是商家(或企
業、公司),她(他)們使用了互聯網的技識訓各種商務網路平臺,完成商務交易的
程序,電子商務是現代 B2B marketing的一種具體主要的表現形式,
案例:阿里巴巴、慧聰網

C2C即 Customer(Consumer) to Customer(Consumer),意思就是消費者個
人間的電子商務行為,比如一個消費者有一臺電腦,通過網路進行交易,把它出售給
另外一個消費者,此種交易型別就稱為C2C電子商務,
案例:淘寶、易趣、瓜子二手車

B2C是Business-to-Customer的縮寫,而其中文簡稱為“商對客”,“商對客”是電子商
務的一種模式,也就是通常說的直接面向消費者銷售產品和服務商業零售模式,這種
形式的電子商務一般以網路零售業為主,主要借助于互聯網開展在線銷售活動,B2C
即企業通過互聯網為消費者提供一個新型的購物環境——網上商店,消費者通過網路
在網上購物、網上支付等消費行為,
注:本專案采用B2C模式

案例:唯品會、樂蜂網B2B2C是一種電子商務型別的網路購物商業模式,B是BUSINESS的簡稱,C是
CUSTOMER的簡稱,第一個B指的是商品或服務的供應商,第二個B指的是從事電子
商務的企業,C則是表示消費者,
案例:京東商城、天貓商城

C2B(Consumer to Business,即消費者到企業),是互聯網經濟時代新的商業模
式,這一模式改變了原有生產者(企業和機構)和消費者的關系,是一種消費者貢獻
價值(Create Value), 企業和機構消費價值(Consume Value),
C2B模式和我們熟知的供需模式(DSM, Demand SupplyModel)恰恰相反,真正的
C2B 應該先有消費者需求產生而后有企業生產,即先有消費者提出需求,后有生產
企業按需求組織生產,通常情況為消費者根據自身需求定制產品和價格,或主動參與
產品設計、生產和定價,產品、價格等彰顯消費者的個性化需求,生產企業進行定制
化生產,
案例:海爾商城、 尚品宅配

O2O即Online To Offline(在線離線/線上到線下),是指將線下的商務機會與互聯
網結合,讓互聯網成為線下交易的平臺,這個概念最早來源于美國,O2O的概念非
常廣泛,既可涉及到線上,又可涉及到線下,可以通稱為O2O,主流商業管理課程均
對O2O這種新型的商業模式有所介紹及關注,
案例:美團、餓了嗎

F2C指的是Factory to customer,即從廠商到消費者的電子商務模式,

2. 青橙-需求分析與系統設計

2.1 需求分析

《青橙》是一個全品類B2C電商平臺(單品類就是只賣一類,比如衣服,化妝品),包含網站前臺和管理后臺兩大部分,網站前臺
包含主站頻道(首頁、搜索、購物車及支付)、用戶中心、秒殺、優惠券等頻道,管理
后臺包含商品、訂單、庫存、用戶、運營、統計、財務、設定等功能
后臺
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述

前臺
在這里插入圖片描述
在這里插入圖片描述
等等,商品詳情頁,登錄頁,評論頁

2.2 系統設計

2.2.1 資料庫分庫設計

(1)商品庫 qingcheng_goods
(2)訂單庫 qingcheng_order
(3)基礎設定庫 qingcheng_config
(4)運營庫 qingcheng_business
(5)用戶庫 qingcheng_user
(6)系統庫qingcheng_system
(7)支付庫 qingcheng_pay
(8)短信庫 qingcheng_sms
2.2.2 技術選型
主框架技術:SSM(通用mapper,比mybatis使用更加簡單)+Dubbo(分布式框架)
前端技術: 網站后臺 Vue.js+ElementUI(ui庫) 網站前臺采用Vue.js 和模板技術 thymeleaf
訊息中間件技術: RabbitMQ
搜索中間件技術: elasticsearch
快取中間件技術: redis
報表插件: echars
安全框架:SpringSecurity
單點登錄中間件 :CAS

2.2.3 系統架構圖

在這里插入圖片描述

3. 通用mapper

3.1 通用mapper簡介

對mybatis進行了進一步封裝,解決mybatis存在的問題
通用 Mapper 是一個可以實作任意 MyBatis 通用方法的框架,專案提供了常規的增
刪改查操作以及Example相關的單表操作,為什么要用通用mapper?我們這里列舉一下
原生Mybatis的痛點:
1、mapper.xml檔案里有大量的sql,當資料庫表欄位變動,組態檔就要修改
2、需要自己實作sql分頁,select * from table where . . . limit 1,3
自己手寫分頁,除了傳參page、pageSize,還需要回傳條目總數count,
3、資料庫可移植性差:如果專案更換資料庫,比如oracle–>mysql,mapper.xml中的
sql要重新寫,因為Oracle的PLSQL 和mysql 支持的函式是不同的,
4、生成的代碼量過大,
5、批量操作,批量插入,批量更新,需要自寫,
而這些,通過通用mapper就可以很輕松的解決了,

3.2 通用mapper快速入門

在線官方檔案:https://gitee.com/free/Mapper/wikis/Home

3.2.1 通用mapper與Spring集成

官方的檔案中介紹了通用mapper的三種使用方式 ,純java使用方式、與Spring集成方
式、與SpringBoot集成方式,這里給大家介紹的是與Spring集成方式,

如果對陳述句抽象化,自動生成,自然能夠避免表不同,資料庫語法不同而帶來的修改問題
同時也可以實作擴展功能,比如自動分頁
也可以批量完成
實作資料庫介面crud呼叫mapper提供的功能介面即可

(1)引入依賴
正常情況下,Spring 和 MyBatis 的集成環境中,應該已經存在下面的依賴:

<dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
        <version>版本號</version>
    </dependency>
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis‐spring</artifactId>
        <version>版本號</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring‐context</artifactId>
        <version>版本號</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring‐tx</artifactId>
        <version>版本號</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring‐jdbc</artifactId>
        <version>版本號</version>
    </dependency>

集成通用 Mapper 在上面的基礎上添加下面的依賴:

  <dependency>
        <groupId>tk.mybatis</groupId>
        <artifactId>mapper</artifactId>
        <version>最新版本</version>
    </dependency>

(2)與spring集成
和通用 Mapper 以前版本一樣,可以直接使用 tk.mybatis 提供
的 tk.mybatis.spring.mapper.MapperScannerConfigurer 進行配置,這個配置和
MyBatis 官方提供的 org.mybatis.spring.mapper.MapperScannerConfigurer 區別只是
第一層的包名, tk 和 org ,所以使用這種方式時,如果你專案已經使用 org. 進行了
配置,只需要改成 tk. 即可,

<bean class="tk.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="掃描包名"/>
    </bean>

專案中采用的是這種xml的配置方式,通用mapper還提供了注解方式的配置,

3.2.2 物體類映射

物體類映射類似下列形式

@Table(name="tb_brand")
    public class Brand implements Serializable{
    @Id
    private Integer id;
    private String name;
    //getter and setter ....
    }

@Table是指定物體類對應的資料庫表 @Id指的是主鍵映射,經過上面簡單的配置后,相
當于就有了 MyBatis 中的關系映射了

3.2.3 創建Mapper介面

 public interface BrandMapper extends Mapper<Brand> {
    }

這里繼承了 tk.mybatis.mapper.common.Mapper 介面,在介面上指定了泛型類
型 Brand ,當你繼承了 Mapper 介面后,此時就已經有了針對 Brand 的大量方法,方
法如下:
在這里插入圖片描述
等等》》》
這些方法中和 MBG 生成的大部分方法都一致,還有一部分 MBG 之外的常用方法,

基礎介面select
List select(T record)
根據T物件中的屬性名稱查詢,類似于select * from table where t.name=#{name} and
t.password = #{password}

T selectOne(T record)
根據物體中的屬性進行查詢,只能有一個回傳值,有多個結果是拋出例外,查詢條件使用等號
T selectByPrimaryKey(Object key)
根據主鍵查詢 說明:根據主鍵欄位進行查詢,方法引數必須包含完整的主鍵屬性,查詢條
件使用等號
int selectCount(T record);
說明:根據物體中的屬性查詢總數,查詢條件使用等號基礎介面insert
int insert(T record);
說明:保存一個物體,null的屬性也會保存,不會使用資料庫默認值
int insertSelective(T record);
說明:保存一個物體,null的屬性不會保存,會使用資料庫默認值

基礎介面Update
int updateByPrimaryKey(T record);
說明:根據主鍵更新物體全部欄位,null值會被更新
int updateByPrimaryKeySelective(T record);
說明:根據主鍵更新屬性不為null的值

基礎介面delete
int delete(T record);
說明:根據物體屬性作為條件進行洗掉,查詢條件使用等號
int deleteByPrimaryKey(Object key);
說明:根據主鍵欄位進行洗掉,方法引數必須包含完整的主鍵屬性

  1. 青橙-工程搭建
    4.1 準備作業
    先進行環境準備
    (1)配置maven本地倉庫
    (2)創建資料庫表
    (3)注冊中心zookeeper
    4.2 模塊依賴關系圖
    我們的工程有三種模塊:(1)公共模塊(解決模塊的重復問題,這里主要是服務層與web層的重復問題,以及模塊重復帶來的復雜性-面向物件的思想) (2)服務層模塊 (3)web層模塊,
    公共模塊主要由公共配置和公共類構成,模塊依賴關系入下圖:
    在這里插入圖片描述

4.3 工程搭建

4.3.1 父工程與公共模塊

(1)創建父工程qingcheng_parent pom.xml
父工程沒有代碼,刪掉src檔案夾

<?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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.qingcheng</groupId>
    <artifactId>qingcheng_parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>qingcheng_common</module>
        <module>qingcheng_common_service</module>
        <module>qingcheng_common_web</module>
        <module>qingcheng_pojo</module>
        <module>qingcheng_interface</module>
        <module>qingcheng_service_goods</module>
        <module>qingcheng_web_manager</module>
    </modules>
    <packaging>pom</packaging>
    <!-- 集中定義依賴版本號 -->
    <properties>
        <junit.version>4.12</junit.version>
        <spring.version>5.0.5.RELEASE</spring.version>
        <pagehelper.version>4.1.4</pagehelper.version>
        <servlet-api.version>2.5</servlet-api.version>
        <dubbo.version>2.6.0</dubbo.version>
        <zookeeper.version>3.4.7</zookeeper.version>
        <zkclient.version>0.1</zkclient.version>
        <mybatis.version>3.4.5</mybatis.version>
        <mybatis.spring.version>1.3.1</mybatis.spring.version>
        <mybatis.paginator.version>1.2.15</mybatis.paginator.version>
        <mysql.version>5.1.32</mysql.version>
        <druid.version>1.0.9</druid.version>
        <commons-fileupload.version>1.3.1</commons-fileupload.version>
        <spring.security.version>5.0.5.RELEASE</spring.security.version>
        <jackson.version>2.9.4</jackson.version>
    </properties>
    <!-- 依賴管理標簽  必須加 -->
    <dependencyManagement>
        <dependencies>
            <!-- Spring -->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</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-webmvc</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-aspects</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>
            <!-- 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>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
            </dependency>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
                <version>1.2.47</version>
            </dependency>
            <dependency>
                <groupId>javassist</groupId>
                <artifactId>javassist</artifactId>
                <version>3.12.1.GA</version>
            </dependency>
            <dependency>
                <groupId>commons-codec</groupId>
                <artifactId>commons-codec</artifactId>
                <version>1.10</version>
            </dependency>
            <dependency>
                <groupId>com.github.pagehelper</groupId>
                <artifactId>pagehelper</artifactId>
                <version>${pagehelper.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>com.github.miemiedev</groupId>
                <artifactId>mybatis-paginator</artifactId>
                <version>${mybatis.paginator.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>
            <!-- 檔案上傳組件 -->
            <dependency>
                <groupId>commons-fileupload</groupId>
                <artifactId>commons-fileupload</artifactId>
                <version>${commons-fileupload.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>
            <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-taglibs</artifactId>
                <version>${spring.security.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-cas</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>com.github.penggle</groupId>
                <artifactId>kaptcha</artifactId>
                <version>2.3.2</version>
                <exclusions>
                    <exclusion>
                        <groupId>javax.servlet</groupId>
                        <artifactId>javax.servlet-api</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>dom4j</groupId>
                <artifactId>dom4j</artifactId>
                <version>1.6.1</version>
            </dependency>
            <dependency>
                <groupId>xml-apis</groupId>
                <artifactId>xml-apis</artifactId>
                <version>1.4.01</version>
            </dependency>
            <!-- 快取 -->
            <dependency>
                <groupId>redis.clients</groupId>
                <artifactId>jedis</artifactId>
                <version>2.9.0</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-redis</artifactId>
                <version>2.0.5.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
                <version>${jackson.version}</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>${jackson.version}</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-annotations</artifactId>
                <version>${jackson.version}</version>
            </dependency>
            <!--通用Mapper-->
            <dependency>
                <groupId>tk.mybatis</groupId>
                <artifactId>mapper</artifactId>
                <version>4.1.4</version>
            </dependency>
            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpclient</artifactId>
                <version>4.5.7</version>
            </dependency>
            <dependency>
                <groupId>com.aliyun.oss</groupId>
                <artifactId>aliyun-sdk-oss</artifactId>
                <version>2.8.2</version>
            </dependency>
            <dependency>
                <groupId>org.elasticsearch.client</groupId>
                <artifactId>elasticsearch-rest-high-level-client</artifactId>
                <version>6.2.1</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.amqp</groupId>
                <artifactId>spring-rabbit</artifactId>
                <version>2.1.4.RELEASE</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>${servlet-api.version}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <!--為了使用jdk1.8新特性,引入,-->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

上面為父
(2)創建公共模塊qingcheng_common,pom.xm
搭建公共模塊,從最頂層開始搭建
提供基礎引數

resources下創建applicationContext-common.xml

<!--用來加載所有檔案名末尾屬性為properties的檔案-->
	<context:property-placeholder location="classpath*:*.properties" />

resources下創建zk.properties
zk.properties

#配置zk連接地址地址
zk.address=127.0.0.1:2181

resources下創建log4j.properties
配置日志引數

(3)創建qingcheng_common_service ,pom.xml
搭建服務公共模塊

<?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>qingcheng_parent</artifactId>
        <groupId>com.qingcheng</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>qingcheng_common_service</artifactId>
    <!--引入common依賴,傳遞依賴,-->
    <dependencies>
        <dependency>
            <groupId>com.qingcheng</groupId>
            <artifactId>qingcheng_common</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <!-- Mybatis -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.miemiedev</groupId>
            <artifactId>mybatis-paginator</artifactId>
        </dependency>
        <!-- MySql -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <!-- 連接池 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
        </dependency>
        <!--通用Mapper-->
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper</artifactId>
        </dependency>
        <!-- 快取 -->
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
        </dependency>

        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>4.1.6</version>
        </dependency>
    </dependencies>

</project>

resources下創建applicationContext-dao.xml,mybatis的

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--資料源的一些配置-->
	<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>
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="plugins">
			<!--mybatis的插件,分頁-->
			<array>
				<bean class="com.github.pagehelper.PageHelper">
					<property name="properties">
						<value>
							dialect=mysql
						</value>
					</property>
				</bean>
			</array>
		</property>
	</bean>
	<!--包掃描-->
	<bean class="tk.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.qingcheng.dao" />
	</bean>

	<!-- 事務管理器  -->
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>
	<!--
        開啟事務控制的注解支持
        注意:此處必須加入proxy-target-class="true",
              需要進行事務控制,會由Spring框架產生代理物件,Dubbo需要將Service發布為服務,要求必須使用cglib創建代理物件,
    -->
	<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>

</beans>

resources下創建applicationContext-dubbo.xml,dubbo的

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc"
	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
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
	<!--指定暴露服務的埠,如果不指定默認為20880-->
	<dubbo:protocol name="dubbo" port="${dubbo.port}"/>
	<dubbo:application name="${dubbo.application}" />
	<!--zk地址為common而來-->
	<dubbo:registry protocol="zookeeper" address="${zk.address}" />
	<dubbo:annotation package="com.qingcheng.service" />
	<!--<context:annotation-config/>-->

	<dubbo:provider timeout="10000" threadpool="fixed" threads="100" accepts="1000"/>
</beans>

redis的

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:cache="http://www.springframework.org/schema/cache"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/cache http://www.springframework.org/schema/beans/spring-cache.xsd">

   <!-- redis 相關配置 --> 
   <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">  
     <property name="maxIdle" value="${redis.maxIdle}" />   
     <property name="maxWaitMillis" value="${redis.maxWait}" />  
     <property name="testOnBorrow" value="${redis.testOnBorrow}" />  
   </bean>  
  <!--spring data redis的配置,使用中會用到組態檔,已經添加-->
   <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
       p:host-name="${redis.host}" p:port="${redis.port}" p:password="${redis.pass}" p:pool-config-ref="poolConfig"/>  
   
   <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">  
    	<property name="connectionFactory" ref="jedisConnectionFactory" />
   </bean>


</beans>  

(4)創建qingcheng_common_web模塊,pom.xml

<?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>qingcheng_parent</artifactId>
        <groupId>com.qingcheng</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
<!--傳遞依賴-->
    <artifactId>qingcheng_common_web</artifactId>
    <dependencies>
        <dependency>
            <groupId>com.qingcheng</groupId>
            <artifactId>qingcheng_common</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.qingcheng</groupId>
            <artifactId>qingcheng_pojo</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <!--檔案上傳相關依賴-->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
        </dependency>
        <!--spring安全依賴-->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
        </dependency>
<!--阿里提供的存盤物件依賴-->
        <dependency>
            <groupId>com.aliyun.oss</groupId>
            <artifactId>aliyun-sdk-oss</artifactId>
        </dependency>

    </dependencies>

</project>

resources下創建applicationContext-json.xml

<mvc:annotation‐driven>
<mvc:message‐converters register‐defaults="true">
<bean
        class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
    <property name="supportedMediaTypes" value="application/json"/>
    <property name="features">
        <list>
            <value>WriteMapNullValue</value>
            <value>WriteDateUseDateFormat</value>
        </list>
    </property>
</bean>
</mvc:message‐converters>
</mvc:annotation‐driven>

resources下創建applicationContext-dubbo.xml

<!-- 參考dubbo 服務,為工程起名字 -->
	<dubbo:application name="${dubbo.application}" />
	<!--對zk地址配置-->
	<dubbo:registry protocol="zookeeper" address="${zk.address}"/>
	<!--掃描所有控制器的類-->
	<dubbo:annotation package="com.qingcheng.controller" />

下面兩個模塊也會被其他模塊所參考,也可以歸類為公共模塊
(5)創建物體層模塊qingcheng_pojo,pom.xml

<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence‐api</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>

(6)創建服務介面層模塊 qingcheng_interface ,pom.xml

<!--jpa注解-->
<dependency>
<groupId>com.qingcheng</groupId>
<artifactId>qingcheng_pojo</artifactId>
<version>1.0‐SNAPSHOT</version>
</dependency>

4.3.2 服務層模塊(商品)

在這里插入圖片描述
其中一個為例子,其他一樣
商品服務
(1)創建qingcheng_service_goods模塊,pom.xml

<dependencies>
    <dependency>
        <groupId>com.qingcheng</groupId>
        <artifactId>qingcheng_interface</artifactId>
        <version>1.0‐SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.qingcheng</groupId>
        <artifactId>qingcheng_common_service</artifactId>
        <version>1.0‐SNAPSHOT</version>
    </dependency>
</dependencies>
<!--指定各個服務的埠,創建各自的服務器,從9001開始-->
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7‐maven‐plugin</artifactId>
            <configuration>
                <!‐‐ 指定埠 ‐‐>
                <port>9001</port>
                <!‐‐ 請求路徑 ‐‐>
                <path>/</path>
            </configuration>
        </plugin>
    </plugins>
</build>

(2)創建webapp/WEB-INF/web.xml

<!DOCTYPE web‐app PUBLIC
"‐//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web‐app_2_3.dtd" >
<web‐app>
<display‐name>Archetype Created Web Application</display‐name>
<!‐‐ 加載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>
</web‐app>

(3)resources下創建dubbo.properties
配置功能區的埠與名字

dubbo.port=20881
dubbo.application=goods

(4)resources下創建db.properties
配置資料庫連接資訊

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/qingcheng_goods?
characterEncoding=utf‐8
jdbc.username=root
jdbc.password=123456

4.3.3 web層(管理后臺)

(1)創建qingcheng_web_manager模塊,pom.xml

<dependencies>
    <dependency>
        <groupId>com.qingcheng</groupId>
        <artifactId>qingcheng_interface</artifactId>
        <version>1.0‐SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.qingcheng</groupId>
        <artifactId>qingcheng_common_web</artifactId>
        <version>1.0‐SNAPSHOT</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7‐maven‐plugin</artifactId>
            <configuration>
                <!‐‐ 指定埠 ‐‐>
                <port>9101</port>
                <!‐‐ 請求路徑 ‐‐>
                <path>/</path>
            </configuration>
        </plugin>
    </plugins>
</build>

(2)創建webapp/WEB-INF/web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <!-- 解決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>
  <!--安全框架的過濾器,暫時不用-->
<!--
  <filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>springSecurityFilterChain</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*:applicationContext*.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>

(3)resources下創建dubbo.properties

dubbo.application=manager

5. 青橙管理后臺-品牌管理后端

5.1 需求分析

實作對品牌的基本操作(增刪改查),只完成后端代碼部分,并通過瀏覽器等工具完成
測驗,

5.2 表結構分析

tb_brand 品牌表
就是品牌類別,圖片地址時品牌的logo
在這里插入圖片描述

5.3 代碼實作

5.3.1 品牌串列

url
/brand/findAll.do
http請求方式
GET
回傳格式

[{
"id": 品牌id,
"name": 品牌名稱,
"image": 品牌圖片地址,
"letter": 品牌的首字母,
"seq": 排序,
},
.......
]

代碼實作:
(1)在qingcheng_pojo工程創建com.qingcheng.pojo包,包下創建物體類

@Table(name="tb_brand")
public class Brand implements Serializable{
    @Id
    private Integer id;//品牌id
    private String name;//品牌名稱
    private String image;//品牌圖片地址
    private String letter;//品牌的首字母
    private Integer seq;//排序
// getter and setter ......
}

(2)qingcheng_service_goods工程創建com.qingcheng.dao,包下創建資料訪問層接

/*資料訪問層,dao*/
public interface BrandMapper extends Mapper<Brand> {
}

(3)qingcheng_interface工程創建com.qingcheng.service.goods包,包下創建業務接

/**
 * 品牌業務邏輯層
 */
public interface BrandService {
    public List<Brand> findAll();
}

(4)qingcheng_service_goods工程創建com.qingcheng.service.impl包,包下創建類

@Service
public class BrandServiceImpl implements BrandService {
    @Autowired
    private BrandMapper brandMapper;
    public List<Brand> findAll() {
        return brandMapper.selectAll();
    }
}

(5)qingcheng_web_manager工程創建com.qingcheng.controller.goods 包,包下創
建類

@RestController
@RequestMapping("/brand")
public class BrandController {
    @Reference
    /*注入遠程的業務介面*/
    private BrandService brandService;
    @GetMapping("/findAll")
    public List<Brand> findAll(){
        return brandService.findAll();
    }
}

測驗

開啟,可以在虛擬機中,也可以本機,zk
在這里插入圖片描述
安裝inferface,pojo
如果變化也要重新安裝

開啟service的tomcat7 run,開啟,開啟manager的tomcat7
在這里插入圖片描述

瀏覽器輸入:http://localhost:9101/brand/findAll.do
資料庫回傳資料,呼叫成功
在這里插入圖片描述

5.3.2 品牌分頁串列

介面定義:
url
/brand/findPage.do
http請求方式
GET
請求引數
在這里插入圖片描述
例子:
GET /brand/findPage.do?page=1&size=10
回傳格式

{rows:[{
        "id": 品牌id,
        "name": 品牌名稱,
        "image": 品牌圖片地址,
        "letter": 品牌的首字母,
        "seq": 排序,
        },
        .......
        ],
        total:100}

pojo是和資料庫對應的類,entity是自己封裝的類,實作自定義資料模塊
創建類pojo,創建功能介面interface,創建實作manager,分步實作
代碼實作:
(1)qingcheng_pojo創建com.qingcheng.entity包,包下創建類
用來承載分頁查詢的物件

/**
 * 分頁結果
 * @param <T>
 */
public class PageResult<T> implements Serializable {
    private Long total;//記錄數
    private List<T> rows;//結果集
    public PageResult(Long total, List<T> rows) {
        this.total = total;
        this.rows = rows;
    }
    public PageResult() {
    }
    public Long getTotal() {
        return total;
    }
    public List<T> getRows() {
        return rows;
    }
    public void setRows(List<T> rows) {
        this.rows = rows;
    }
    public void setTotal(Long total) {
        this.total = total;
    }
}

(2)qingcheng_interface工程BrandService介面新增方法

public PageResult<Brand> findPage(int page, int size);

(3)qingcheng_service_goods工程BrandServiceImpl新增方法

/**
 * 分頁查詢
 * @param page 頁碼
 * @param size 每頁記錄數
 * @return 分頁結果
 */
public PageResult<Brand> findPage(int page, int size) {
        PageHelper.startPage(page,size);
        Page<Brand> brands = (Page<Brand>) brandMapper.selectAll();
        return new PageResult<Brand>
(brands.getTotal(),brands.getResult());
        }

(4)qingcheng_web_manager工程BrandController新增方法

@GetMapping("/findPage")
public PageResult<Brand> findPage(int page, int size){
        return brandService.findPage(page, size);
        }

因為更新了interface與pojo,所以需要重新安裝
啟動工程,瀏覽器測驗:http://localhost:9101/brand/findPage.do?page=1&size=10
在這里插入圖片描述

5.3.3 品牌條件查詢

url
/brand/findList.do
http請求方式
POST
請求引數
在這里插入圖片描述
例子:

POST /brand/findList.do
        {
        "name": 品牌名稱,
        "letter": 品牌的首字母
        }

回傳格式

[{
        "id": 品牌id,
        "name": 品牌名稱,
        "image": 品牌圖片地址,
        "letter": 品牌的首字母,
        "seq": 排序,
        },
        .......
        ]

代碼實作:
(1)qingcheng_interface工程BrandService介面新增方法

public List<Brand> findList(Map<String, Object> searchMap);

(2)qingcheng_service_goods工程BrandServiceImpl新增方法

/**
 * 條件查詢
 * @param searchMap 查詢條件
 * @return
 */
public List<Brand> findList(Map<String, Object> searchMap) {
        Example example = createExample(searchMap);
        return brandMapper.selectByExample(example);
        }
/**
 * 構建查詢條件
 * @param searchMap
 * @return
 */
private Example createExample(Map<String, Object> searchMap){
        Example example=new Example(Brand.class);
        Example.Criteria criteria = example.createCriteria();
        if(searchMap!=null){
//名稱條件
        if(searchMap.get("name")!=null &&
        !"".equals(searchMap.get("name"))){
        criteria.andLike("name","%"+
        (String)searchMap.get("name")+"%");
        }
//首字母
        if(searchMap.get("letter")!=null &&
        !"".equals(searchMap.get("letter"))){
        criteria.andEqualTo("letter",
        (String)searchMap.get("letter"));
        }
        }
        return example;
        }

(3)qingcheng_web_manager工程BrandController新增方法

 @PostMapping("/findList")
    /*加入注解,分解請求得到的json資料*/
    /*之前都是get請求的,輸入條件引數,現在post請求*/
    public List<Brand> findList( @RequestBody Map searchMap){
        return brandService.findList(searchMap);
    }

/之前都是get請求的,輸入條件引數,現在post請求/
使用postman
在這里插入圖片描述
以json方式請求,
在這里插入圖片描述
多個條件加逗號即可

5.3.4 品牌條件+分頁查詢

寫一個功能函式囊括以上兩個功能即可
url
/brand/findPage.do
http請求方式
POST
請求引數

在這里插入圖片描述
例子:

POST /brand/findPage.do?page=1&size=10
        {
        "name": 品牌名稱,
        "letter": 品牌的首字母
        }

回傳格式:

{rows:[{
        "id": 品牌id,
        "name": 品牌名稱,
        "image": 品牌圖片地址,
        "letter": 品牌的首字母,
        "seq": 排序
        },
        .......
        ],
        total:100}

代碼實作:
(1)qingcheng_interface工程BrandService介面新增方法

public PageResult<Brand> findPage(Map<String,Object> searchMap,int page,
        int size);

(2)qingcheng_service_goods工程BrandServiceImpl新增方法

/**
 * 分頁+條件查詢
 * @param searchMap
 * @param page
 * @param size
 * @return
 */
public PageResult<Brand> findPage(Map<String, Object> searchMap, int
        page, int size) {
        PageHelper.startPage(page,size);
        Example example = createExample(searchMap);
        Page<Brand> brands = (Page<Brand>)
        brandMapper.selectByExample(example);
        return new PageResult<Brand>
(brands.getTotal(),brands.getResult());
        }

(3)qingcheng_web_manager工程BrandController新增方法

@PostMapping("/findPage")
public PageResult<Brand> findPage(@RequestBody Map<String,Object>
searchMap,int page, int size){
        return brandService.findPage(searchMap,page,size);
        }

使用了多型,將findPage執行了分頁與條件的多次撰寫
在這里插入圖片描述

5.3.5 根據ID查詢品牌

url
/brand/findById.do
http請求方式
GET
請求引數
在這里插入圖片描述

代碼實作:
(1)qingcheng_interface工程BrandService介面新增方法

public Brand findById(Integer id);

(2)qingcheng_service_goods工程BrandServiceImpl新增方法
介面,實作,網址映射

/**
 * 根據Id查詢
 * @param id
 * @return
 */
public Brand findById(Integer id) {
        return brandMapper.selectByPrimaryKey(id);
        }

(3)qingcheng_web_manager工程BrandController新增方法

@GetMapping("/findById")
public Brand findById(Integer id){
        return brandService.findById(id);
        }

在這里插入圖片描述

5.3.6 品牌新增

(1)qingcheng_pojo 新增類

/**
 * 回傳前端的訊息封裝,正確錯誤都有資訊了
 */
public class Result implements Serializable {
    private Integer code;//回傳的業務碼 0:成功執行 1:發生錯誤
    private String message;//資訊
    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }
    public Result() {
        this.code=0;
        this.message = "執行成功";
    }
    public Integer getCode() {
        return code;
    }
    public void setCode(Integer code) {
        this.code = code;
    }
    public String getMessage() {
        return message;
    }
    public void setMessage(String message) {
        this.message = message;
    }
}

(2)qingcheng_interface工程BrandService介面新增方法

public void add(Brand brand);

(3)qingcheng_service_goods工程BrandServiceImpl新增方法

/**
 * 新增
 * @param brand
 */
public void add(Brand brand) {
        brandMapper.insert(brand);
        }

(4)qingcheng_web_manager工程BrandController新增方法

@PostMapping("/add")
public Result add(@RequestBody Brand brand){
        brandService.add(brand);
        return new Result();
        }

在這里插入圖片描述

5.3.7 品牌修改

對于修改的方法,
第一個根據條件更新,第二個是如果有null值會被忽略,如果包含null值會被覆寫還是忽略,第四個為忽略,更加實用,不覆寫該資料庫原來的資料
在這里插入圖片描述

(1)qingcheng_interface工程BrandService介面新增方法

public void update(Brand brand);

(2)qingcheng_service_goods工程BrandServiceImpl新增方法

/**
 * 修改
 * @param brand
 */
public void update(Brand brand) {
        brandMapper.updateByPrimaryKeySelective(brand);
        }

(3)qingcheng_web_manager工程BrandController新增方法

@PostMapping("/update")
public Result update(@RequestBody Brand brand){
        brandService.update(brand);
        return new Result();
        }

5.3.8 品牌洗掉

url
/brand/delete.do
http請求方式
GET
請求引數
在這里插入圖片描述

例子:

GET /brand/delete.do?id=1

回傳格式:

{
        code:0,
        message:""
        }

code為0表示成功,為1表示失敗
代碼實作:
(1)qingcheng_interface工程BrandService介面新增方法

public void delete(Integer id);

(2)qingcheng_service_goods工程BrandServiceImpl新增方法

/**
 * 洗掉
 * @param id
 */
public void delete(Integer id) {
        brandMapper.deleteByPrimaryKey(id);
        }

(3)qingcheng_web_manager工程BrandController新增方法

@GetMapping("/delete")
public Result delete(Integer id){
        brandService.delete(id);
        return new Result();
        }

以上主要是為了嘗試,通用mapper的方法

6. 公共例外處理

應該將專案所有的例外,進行統一管理
qingcheng_common_web工程創建com.qingcheng.controller包,包下創建類

/**
 * 統一例外處理類
 */
@ControllerAdvice
public class BaseExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e) {
        e.printStackTrace();
        System.out.println("呼叫了公共例外處理類");
        return new Result(1,e.getMessage());
    }
}

注意回顧系統架構圖,所有的都是圍繞其展開

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/277713.html

標籤:其他

上一篇:【筆記】Vuex 快速入門

下一篇:2021最適合Java程式員學習路線,面經和面試題1000道

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 面試突擊第一季,第二季,第三季

    第一季必考 https://www.bilibili.com/video/BV1FE411y79Y?from=search&seid=15921726601957489746 第二季分布式 https://www.bilibili.com/video/BV13f4y127ee/?spm_id_fro ......

    uj5u.com 2020-09-10 05:35:24 more
  • 第三單元作業總結

    1.前言 這應該是本學期最后一次寫作業總結了吧。總體來說,對作業的節奏也差不多掌握了,作業做起來的效率也更高了。雖然和之前的作業一樣,作業中都要用到新的知識,但是相比之前,更加懂得了如何利用工具以及資料。雖然之間卡過殼,但總體而言,這幾次作業還算完成的比較好。 2.作業程序總結 相比前兩個單元,此單 ......

    uj5u.com 2020-09-10 05:35:41 more
  • 北航OO(2020)第四單元博客作業暨課程總結博客

    北航OO(2020)第四單元博客作業暨課程總結博客 本單元作業的架構設計 在本單元中,由于UML圖具有比較清晰的樹形結構,因此我對其中需要進行查詢操作的元素進行了包裝,在樹的父節點中存盤所有孩子的參考。考慮到性能問題,我采用了快取機制,一次查詢后盡可能快取已經遍歷過的資訊,以減少遍歷次數。 本單元我 ......

    uj5u.com 2020-09-10 05:35:48 more
  • BUAA_OO_第四單元

    一、UML決議器設計 ? 先看下題目:第四單元實作一個基于JDK 8帶有效性檢查的UML(Unified Modeling Language)類圖,順序圖,狀態圖分析器 MyUmlInteraction,實際上我們要建立一個有向圖模型,UML中的物件(元素)可能與同級元素連接,也可與低級元素相連形成 ......

    uj5u.com 2020-09-10 05:35:54 more
  • 6.1邏輯運算子

    邏輯運算子 1. && 短路與 運算式1 && 運算式2 01.運算式1為true并且運算式2也為true 整體回傳為true 02.運算式1為false,將不會執行運算式2 整體回傳為false 03.只要有一個運算式為false 整體回傳為false 2. || 短路或 運算式1 || 運算式2 ......

    uj5u.com 2020-09-10 05:35:56 more
  • BUAAOO 第四單元 & 課程總結

    1. 第四單元:StarUml檔案決議 本單元采用了圖模型決議UML。 UML檔案可以抽象為圖、子圖、邊的邏輯結構。 在實作中,圖的節點包括類、介面、屬性,子圖包括狀態圖、順序圖等。 采用了三次遍歷UML元素的方法建圖,第一遍遍歷建點,第二、三次遍歷設定屬性、連邊,實作圖物件的初始化。這里借鑒了一些 ......

    uj5u.com 2020-09-10 05:36:06 more
  • 談談我對C# 多型的理解

    面向物件三要素:封裝、繼承、多型。 封裝和繼承,這兩個比較好理解,但要理解多型的話,可就稍微有點難度了。今天,我們就來講講多型的理解。 我們應該經常會看到面試題目:請談談對多型的理解。 其實呢,多型非常簡單,就一句話:呼叫同一種方法產生了不同的結果。 具體實作方式有三種。 一、多載 多載很簡單。 p ......

    uj5u.com 2020-09-10 05:36:09 more
  • Python 資料驅動工具:DDT

    背景 python 的unittest 沒有自帶資料驅動功能。 所以如果使用unittest,同時又想使用資料驅動,那么就可以使用DDT來完成。 DDT是 “Data-Driven Tests”的縮寫。 資料:http://ddt.readthedocs.io/en/latest/ 使用方法 dd. ......

    uj5u.com 2020-09-10 05:36:13 more
  • Python里面的xlrd模塊詳解

    那我就一下面積個問題對xlrd模塊進行學習一下: 1.什么是xlrd模塊? 2.為什么使用xlrd模塊? 3.怎樣使用xlrd模塊? 1.什么是xlrd模塊? ?python操作excel主要用到xlrd和xlwt這兩個庫,即xlrd是讀excel,xlwt是寫excel的庫。 今天就先來說一下xl ......

    uj5u.com 2020-09-10 05:36:28 more
  • 當我們創建HashMap時,底層到底做了什么?

    jdk1.7中的底層實作程序(底層基于陣列+鏈表) 在我們new HashMap()時,底層創建了默認長度為16的一維陣列Entry[ ] table。當我們呼叫map.put(key1,value1)方法向HashMap里添加資料的時候: 首先,呼叫key1所在類的hashCode()計算key1 ......

    uj5u.com 2020-09-10 05:36:38 more
最新发布
  • 【中介者設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

    * 中介者模式是一種行為型設計模式,它可以用來減少類之間的直接依賴關系,
    * 將物件之間的通信封裝到一個中介者物件中,從而使得各個物件之間的關系更加松散。
    * 在中介者模式中,物件之間不再直接相互互動,而是通過中介者來中轉訊息。 ......

    uj5u.com 2023-04-20 08:20:47 more
  • 露天煤礦現場調研和交流案例分享

    他們集團的資訊化公司及研究院在一個礦區正在做智能礦山的統一平臺的 試點,專案投資大概1億,包括了礦山的各方面的內容,顯示得我們這次交流有點多余。他們2年前開始做智能礦山的規劃,有很多煤礦行業專家的加持,他們的描述是非常完美,但是去年底應該上線的平臺,現在還沒有看到影子。他們確實有很多場景需求,但是被... ......

    uj5u.com 2023-04-20 08:20:25 more
  • 《社區人員管理》實戰案例設計&個人案例分享

    設計是一個讓人夢想成真程序,開始編碼、測驗、除錯之前進行需求分析和架構設計,才能保證關鍵方面都做正確 ......

    uj5u.com 2023-04-20 08:20:17 more
  • 軟體架構生態化-多角色交付的探索實踐

    作為一個技術架構師,不僅僅要緊跟行業技術趨勢,還要結合研發團隊現狀及痛點,探索新的交付方案。在日常中,你是否遇到如下問題 “ 業務需求排期長研發是瓶頸;非研發角色感受不到研發技改提效的變化;引入ISV 團隊又擔心質量和安全,培訓周期長“等等,基于此我們探索了一種新的技術體系及交付方案來解決如上問題。 ......

    uj5u.com 2023-04-20 08:20:10 more
  • 【中介者設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

    * 中介者模式是一種行為型設計模式,它可以用來減少類之間的直接依賴關系,
    * 將物件之間的通信封裝到一個中介者物件中,從而使得各個物件之間的關系更加松散。
    * 在中介者模式中,物件之間不再直接相互互動,而是通過中介者來中轉訊息。 ......

    uj5u.com 2023-04-20 08:19:44 more
  • 露天煤礦現場調研和交流案例分享

    他們集團的資訊化公司及研究院在一個礦區正在做智能礦山的統一平臺的 試點,專案投資大概1億,包括了礦山的各方面的內容,顯示得我們這次交流有點多余。他們2年前開始做智能礦山的規劃,有很多煤礦行業專家的加持,他們的描述是非常完美,但是去年底應該上線的平臺,現在還沒有看到影子。他們確實有很多場景需求,但是被... ......

    uj5u.com 2023-04-20 08:19:07 more
  • 《社區人員管理》實戰案例設計&個人案例分享

    設計是一個讓人夢想成真程序,開始編碼、測驗、除錯之前進行需求分析和架構設計,才能保證關鍵方面都做正確 ......

    uj5u.com 2023-04-20 08:18:57 more
  • 軟體架構生態化-多角色交付的探索實踐

    作為一個技術架構師,不僅僅要緊跟行業技術趨勢,還要結合研發團隊現狀及痛點,探索新的交付方案。在日常中,你是否遇到如下問題 “ 業務需求排期長研發是瓶頸;非研發角色感受不到研發技改提效的變化;引入ISV 團隊又擔心質量和安全,培訓周期長“等等,基于此我們探索了一種新的技術體系及交付方案來解決如上問題。 ......

    uj5u.com 2023-04-20 08:18:49 more
  • 05單件模式

    #經典的單件模式 public class Singleton { private static Singleton uniqueInstance; //一個靜態變數持有Singleton類的唯一實體。 // 其他有用的實體變數寫在這里 //構造器宣告為私有,只有Singleton可以實體化這個類! ......

    uj5u.com 2023-04-19 08:42:51 more
  • 【架構與設計】常見微服務分層架構的區別和落地實踐

    軟體工程的方方面面都遵循一個最基本的道理:沒有銀彈,架構分層模型更是如此,每一種都有各自優缺點,所以請根據不同的業務場景,并遵循簡單、可演進這兩個重要的架構原則選擇合適的架構分層模型即可。 ......

    uj5u.com 2023-04-19 08:42:41 more