• 十四、商城 - 商城架构-SSM(2)


    一、商城 - 商城架构

    1.1 工程结构分析与设计

    在这里插入图片描述

    工程说明:

    • youlexuan_parent 聚合工程
    • youlexuan_pojo 通用实体类层
    • youlexuan_dao 通用数据访问层
    • youlexuan_xxxxx_interface 某服务层接口
    • youlexuan_xxxxx_service 某服务层实现
    • youlexuan_xxxxx_web 某web工程

    1.2 创建数据库表

    创建 youlexuan 数据库而后执行 youlexuan_db.sql

    1.3 搭建框架

    1.3.1 父工程

    • 创建Maven工程 (POM) ,
    • groupId 为com.zql,
    • artifactId 为 youlexuan_parent ,

    maven 的准备

    在这里插入图片描述
    在这里插入图片描述

    在这里插入图片描述

    在pom.xml中添加锁定版本信息 dependencyManagement 与 pluginManagement。

    以下模块均继承自此父工程

    
    <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.0modelVersion>
    
        <groupId>com.zqlgroupId>
        <artifactId>youlexuan_parentartifactId>
        <version>1.0version>
        <packaging>pompackaging>
    
        
        <properties>
            <commons.io.version>2.1commons.io.version>
            <junit.version>4.12junit.version>
            <spring.version>4.2.4.RELEASEspring.version>
            <pagehelper.version>4.0.0pagehelper.version>
            <servlet-api.version>2.5servlet-api.version>
            <dubbo.version>2.6.4dubbo.version>
            <zookeeper.version>3.4.10zookeeper.version>
            <curator-recipes.version>4.0.1curator-recipes.version>
            <mybatis.version>3.2.8mybatis.version>
            <mybatis.spring.version>1.2.2mybatis.spring.version>
            <mysql.version>5.1.32mysql.version>
            <druid.version>1.0.9druid.version>
            <commons-fileupload.version>1.3.1commons-fileupload.version>
            <freemarker.version>2.3.23freemarker.version>
            <activemq.version>5.11.2activemq.version>
            <security.version>3.2.3.RELEASEsecurity.version>
            <solrj.version>4.10.3solrj.version>
            <ik.version>2012_u6ik.version>
        properties>
    
        <dependencyManagement>
            <dependencies>
            
                
                <dependency>
                    <groupId>org.springframeworkgroupId>
                    <artifactId>spring-contextartifactId>
                    <version>${spring.version}version>
                dependency>
                <dependency>
                    <groupId>org.springframeworkgroupId>
                    <artifactId>spring-beansartifactId>
                    <version>${spring.version}version>
                dependency>
                <dependency>
                    <groupId>org.springframeworkgroupId>
                    <artifactId>spring-webmvcartifactId>
                    <version>${spring.version}version>
                dependency>
                <dependency>
                    <groupId>org.springframeworkgroupId>
                    <artifactId>spring-jdbcartifactId>
                    <version>${spring.version}version>
                dependency>
                <dependency>
                    <groupId>org.springframeworkgroupId>
                    <artifactId>spring-aspectsartifactId>
                    <version>${spring.version}version>
                dependency>
                <dependency>
                    <groupId>org.springframeworkgroupId>
                    <artifactId>spring-jmsartifactId>
                    <version>${spring.version}version>
                dependency>
                <dependency>
                    <groupId>org.springframeworkgroupId>
                    <artifactId>spring-context-supportartifactId>
                    <version>${spring.version}version>
                dependency>
                <dependency>
                    <groupId>org.springframeworkgroupId>
                    <artifactId>spring-testartifactId>
                    <version>${spring.version}version>
                dependency>
                <dependency>
                    <groupId>org.springframeworkgroupId>
                    <artifactId>spring-webartifactId>
                    <version>${spring.version}version>
                dependency>
                
                <dependency>
                    <groupId>com.alibabagroupId>
                    <artifactId>dubboartifactId>
                    <version>${dubbo.version}version>
                dependency>
                <dependency>
                    <groupId>org.apache.zookeepergroupId>
                    <artifactId>zookeeperartifactId>
                    <version>${zookeeper.version}version>
                dependency>
                <dependency>
                    <groupId>org.apache.curatorgroupId>
                    <artifactId>curator-recipesartifactId>
                    <version>${curator-recipes.version}version>
                dependency>
                <dependency>
                    <groupId>junitgroupId>
                    <artifactId>junitartifactId>
                    <version>4.12version>
                dependency>
                <dependency>
                    <groupId>com.alibabagroupId>
                    <artifactId>fastjsonartifactId>
                    <version>1.2.28version>
                dependency>
                <dependency>
                    <groupId>javassistgroupId>
                    <artifactId>javassistartifactId>
                    <version>3.11.0.GAversion>
                dependency>
                <dependency>
                    <groupId>commons-codecgroupId>
                    <artifactId>commons-codecartifactId>
                    <version>1.10version>
                dependency>
                <dependency>
                    <groupId>javax.servletgroupId>
                    <artifactId>servlet-apiartifactId>
                    <version>2.5version>
                    <scope>providedscope>
                dependency>
                <dependency>
                    <groupId>com.github.pagehelpergroupId>
                    <artifactId>pagehelperartifactId>
                    <version>${pagehelper.version}version>
                dependency>
                
                <dependency>
                    <groupId>org.mybatisgroupId>
                    <artifactId>mybatisartifactId>
                    <version>${mybatis.version}version>
                dependency>
                <dependency>
                    <groupId>org.mybatisgroupId>
                    <artifactId>mybatis-springartifactId>
                    <version>${mybatis.spring.version}version>
                dependency>
                
                <dependency>
                    <groupId>mysqlgroupId>
                    <artifactId>mysql-connector-javaartifactId>
                    <version>${mysql.version}version>
                dependency>
                
                <dependency>
                    <groupId>com.alibabagroupId>
                    <artifactId>druidartifactId>
                    <version>${druid.version}version>
                dependency>
                <dependency>
                    <groupId>org.csource.fastdfsgroupId>
                    <artifactId>fastdfsartifactId>
                    <version>1.2version>
                dependency>
                
                <dependency>
                    <groupId>commons-fileuploadgroupId>
                    <artifactId>commons-fileuploadartifactId>
                    <version>${commons-fileupload.version}version>
                dependency>
    
                <dependency>
                    <groupId>commons-iogroupId>
                    <artifactId>commons-ioartifactId>
                    <version>${commons.io.version}version>
                dependency>
                
                
                <dependency>
                    <groupId>redis.clientsgroupId>
                    <artifactId>jedisartifactId>
                    <version>2.8.1version>
                dependency>
                <dependency>
                    <groupId>org.springframework.datagroupId>
                    <artifactId>spring-data-redisartifactId>
                    <version>1.7.2.RELEASEversion>
                dependency>
                <dependency>
                    <groupId>org.freemarkergroupId>
                    <artifactId>freemarkerartifactId>
                    <version>${freemarker.version}version>
                dependency>
                <dependency>
                    <groupId>org.apache.activemqgroupId>
                    <artifactId>activemq-allartifactId>
                    <version>${activemq.version}version>
                dependency>
                
                <dependency>
                    <groupId>org.springframework.securitygroupId>
                    <artifactId>spring-security-webartifactId>
                    <version>4.1.0.RELEASEversion>
                dependency>
                <dependency>
                    <groupId>org.springframework.securitygroupId>
                    <artifactId>spring-security-configartifactId>
                    <version>4.1.0.RELEASEversion>
                dependency>
                <dependency>
                    <groupId>com.github.pengglegroupId>
                    <artifactId>kaptchaartifactId>
                    <version>2.3.2version>
                    <exclusions>
                        <exclusion>
                            <groupId>javax.servletgroupId>
                            <artifactId>javax.servlet-apiartifactId>
                        exclusion>
                    exclusions>
                dependency>
                <dependency>
                    <groupId>org.springframework.securitygroupId>
                    <artifactId>spring-security-casartifactId>
                    <version>4.1.0.RELEASEversion>
                dependency>
                <dependency>
                    <groupId>org.jasig.cas.clientgroupId>
                    <artifactId>cas-client-coreartifactId>
                    <version>3.3.3version>
                    
                    <exclusions>
                        <exclusion>
                            <groupId>org.slf4jgroupId>
                            <artifactId>log4j-over-slf4jartifactId>
                        exclusion>
                    exclusions>
                dependency>
                
                <dependency>
                    <groupId>org.apache.solrgroupId>
                    <artifactId>solr-solrjartifactId>
                    <version>${solrj.version}version>
                dependency>
                <dependency>
                    <groupId>com.janeluogroupId>
                    <artifactId>ikanalyzerartifactId>
                    <version>${ik.version}version>
                dependency>
                <dependency>
                    <groupId>org.apache.httpcomponentsgroupId>
                    <artifactId>httpcoreartifactId>
                    <version>4.4.4version>
                dependency>
                <dependency>
                    <groupId>org.apache.httpcomponentsgroupId>
                    <artifactId>httpclientartifactId>
                    <version>4.5.3version>
                dependency>
                <dependency>
                    <groupId>dom4jgroupId>
                    <artifactId>dom4jartifactId>
                    <version>1.6.1version>
                dependency>
                <dependency>
                    <groupId>xml-apisgroupId>
                    <artifactId>xml-apisartifactId>
                    <version>1.4.01version>
                dependency>
            dependencies>
        dependencyManagement>
    project>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264

    1.3.2 通用实体类模块

    创建通用实体类模块 youlexuan_pojo

    在这里插入图片描述

    1.3.3 通用数据访问模块

    1、创建通用数据访问模块 youlexuan_dao

    在这里插入图片描述
    2、添加依赖Mybatis和youlexuan_pojo

    
    <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>youlexuan_parentartifactId>
            <groupId>com.zqlgroupId>
            <version>1.0version>
        parent>
        <modelVersion>4.0.0modelVersion>
    
        <artifactId>youlexuan_daoartifactId>
    
        <dependencies>
            
            <dependency>
                <groupId>org.mybatisgroupId>
                <artifactId>mybatisartifactId>
            dependency>
            <dependency>
                <groupId>org.mybatisgroupId>
                <artifactId>mybatis-springartifactId>
            dependency>
            <dependency>
                <groupId>com.github.pagehelpergroupId>
                <artifactId>pagehelperartifactId>
            dependency>
            
            <dependency>
                <groupId>mysqlgroupId>
                <artifactId>mysql-connector-javaartifactId>
            dependency>
            
            <dependency>
                <groupId>com.alibabagroupId>
                <artifactId>druidartifactId>
            dependency>
            <dependency>
                <groupId>com.zqlgroupId>
                <artifactId>youlexuan_pojoartifactId>
                <version>1.0version>
            dependency>
        dependencies>
    
    project>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45

    3、拷贝 数据访问层配置文件

    在这里插入图片描述

    1.3.4 通用工具类模块

    创建通用工具类模块 youlexuan_common

    在这里插入图片描述

    1.3.5 商家商品服务接口模块

    创建maven(jar)模块 youlexuan_sellergoods_interface

    在这里插入图片描述

    pom.xml添加依赖

    <dependencies>
        <dependency>
            <groupId>com.zqlgroupId>
            <artifactId>youlexuan_daoartifactId>
            <version>1.0version>
        dependency>
    dependencies>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    1.3.6 商家商品服务模块

    1、创建maven(war)模块 youlexuan_sellergoods_service

    在这里插入图片描述
    2、pom.xml引入依赖 (注:要加 war)

    
    <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>youlexuan_parentartifactId>
            <groupId>com.zqlgroupId>
            <version>1.0version>
        parent>
        <modelVersion>4.0.0modelVersion>
    
        <artifactId>youlexuan_sellergoods_serviceartifactId>
    
        <packaging>warpackaging>
        <properties>
            <webVersion>3.0webVersion>
        properties>
        <dependencies>
            
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-contextartifactId>
            dependency>
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-beansartifactId>
            dependency>
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-webmvcartifactId>
            dependency>
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-jdbcartifactId>
            dependency>
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-aspectsartifactId>
            dependency>
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-jmsartifactId>
            dependency>
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-context-supportartifactId>
            dependency>
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-testartifactId>
            dependency>
            
            <dependency>
                <groupId>com.alibabagroupId>
                <artifactId>dubboartifactId>
            dependency>
            <dependency>
                <groupId>org.apache.zookeepergroupId>
                <artifactId>zookeeperartifactId>
            dependency>
            <dependency>
                <groupId>org.apache.curatorgroupId>
                <artifactId>curator-recipesartifactId>
            dependency>
            <dependency>
                <groupId>junitgroupId>
                <artifactId>junitartifactId>
            dependency>
            <dependency>
                <groupId>com.alibabagroupId>
                <artifactId>fastjsonartifactId>
            dependency>
            <dependency>
                <groupId>javassistgroupId>
                <artifactId>javassistartifactId>
            dependency>
            <dependency>
                <groupId>commons-codecgroupId>
                <artifactId>commons-codecartifactId>
            dependency>
            <dependency>
                <groupId>javax.servletgroupId>
                <artifactId>servlet-apiartifactId>
                <scope>providedscope>
            dependency>
            <dependency>
                <groupId>com.zqlgroupId>
                <artifactId>youlexuan_commonartifactId>
                <version>1.0version>
            dependency>
            <dependency>
                <groupId>com.zqlgroupId>
                <artifactId>youlexuan_daoartifactId>
                <version>1.0version>
            dependency>
            <dependency>
                <groupId>com.zqlgroupId>
                <artifactId>youlexuan_sellergoods_interfaceartifactId>
                <version>1.0version>
            dependency>
        dependencies>
        <build>
            <plugins>
                
                <plugin>
                    <groupId>org.apache.tomcat.mavengroupId>
                    <artifactId>tomcat7-maven-pluginartifactId>
                    <configuration>
                        <path>/path>
                        <port>9001port>
                    configuration>
                plugin>
            plugins>
        build>
    project>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115

    3、创建spring配置文件

    创建包 com.zql.sellergoods.service.impl

    在src/main/resources下创建 spring/applicationContext_service.xml

    
    <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">
    
        <dubbo:protocol name="dubbo" port="20881">dubbo:protocol>
        <dubbo:application name="youlexuan_sellergoods_service"/>
        <dubbo:registry address="zookeeper://192.168.188.180:2181"/>
        <dubbo:annotation package="com.zql.sellergoods.service.impl" />
    beans>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    4、创建web.xml

    在webapps下创建WEB-INF/web.xml ,加载spring容器

    在这里插入图片描述

    
    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
             version="4.0">
    
        
        <context-param>
            <param-name>contextConfigLocationparam-name>
            <param-value>classpath*:spring/applicationContext_*.xmlparam-value>
        context-param>
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
        listener>
    web-app>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    注意:加载spring配置文件必须增加classpath*:spring/applicationContext*.xml
    要不然加载数据库驱动会保存。

    1.3.7 运营商管理后台

    创建maven(war)模块 youlexuan_manager_web

    在这里插入图片描述
    1、pom.xml引入依赖 (注:要加 war)

    
    <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>youlexuan_parentartifactId>
            <groupId>com.zqlgroupId>
            <version>1.0version>
        parent>
        <modelVersion>4.0.0modelVersion>
    
        <artifactId>youlexuan_manager_webartifactId>
        
        <packaging>warpackaging>
        <properties>
            <webVersion>3.0webVersion>
        properties>
        <dependencies>
            
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-contextartifactId>
            dependency>
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-beansartifactId>
            dependency>
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-webmvcartifactId>
            dependency>
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-jdbcartifactId>
            dependency>
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-aspectsartifactId>
            dependency>
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-jmsartifactId>
            dependency>
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-context-supportartifactId>
            dependency>
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-testartifactId>
            dependency>
            
            <dependency>
                <groupId>com.alibabagroupId>
                <artifactId>dubboartifactId>
            dependency>
            <dependency>
                <groupId>org.apache.zookeepergroupId>
                <artifactId>zookeeperartifactId>
            dependency>
            <dependency>
                <groupId>org.apache.curatorgroupId>
                <artifactId>curator-recipesartifactId>
            dependency>
            <dependency>
                <groupId>junitgroupId>
                <artifactId>junitartifactId>
            dependency>
            <dependency>
                <groupId>com.alibabagroupId>
                <artifactId>fastjsonartifactId>
            dependency>
            <dependency>
                <groupId>javassistgroupId>
                <artifactId>javassistartifactId>
            dependency>
            <dependency>
                <groupId>commons-codecgroupId>
                <artifactId>commons-codecartifactId>
            dependency>
            <dependency>
                <groupId>javax.servletgroupId>
                <artifactId>servlet-apiartifactId>
                <scope>providedscope>
            dependency>
            <dependency>
                <groupId>com.zqlgroupId>
                <artifactId>youlexuan_commonartifactId>
                <version>1.0version>
            dependency>
            <dependency>
                <groupId>com.zqlgroupId>
                <artifactId>youlexuan_sellergoods_interfaceartifactId>
                <version>1.0version>
            dependency>
        dependencies>
        <build>
            <plugins>
                
                <plugin>
                    <groupId>org.apache.tomcat.mavengroupId>
                    <artifactId>tomcat7-maven-pluginartifactId>
                    <configuration>
                        <path>/path>
                        <port>9101port>
                    configuration>
                plugin>
            plugins>
        build>
    
    project>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111

    2、创建 springmvc 配置文件

    创建包 com.zql.sellergoods.controller

    在src/main/resources下创建 spring/springmvc.xml

    
    <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:mvc="http://www.springframework.org/schema/mvc"
           xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
           xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
    		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
    		http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd
    		http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
        <context:component-scan base-package="com.zql.sellergoods.controller"/>
    
        <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">
                        <array>
                            <value>WriteMapNullValuevalue>
                            <value>WriteDateUseDateFormatvalue>
                        array>
                    property>
                bean>
            mvc:message-converters>
        mvc:annotation-driven>
        
        <dubbo:application name="youlexuan_manager_web" />
        <dubbo:registry address="zookeeper://192.168.188.180:2181"/>
        <dubbo:annotation package="com.zql.sellergoods.controller" />
    beans>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    注意配置:fastjSON处理json

    3、创建web.xml

    在webapps下创建WEB-INF/web.xml ,加载spring容器

    在这里插入图片描述

    
    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
             version="4.0">
    
        <servlet>
            <servlet-name>springmvcservlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
            <init-param>
                <param-name>contextConfigLocationparam-name>
                <param-value>classpath:spring/springmvc.xmlparam-value>
            init-param>
        servlet>
        <servlet-mapping>
            <servlet-name>springmvcservlet-name>
            <url-pattern>*.dourl-pattern>
        servlet-mapping>
        <context-param>
            <param-name>contextConfigLocationparam-name>
            <param-value>classpath:spring/spring-*.xmlparam-value>
        context-param>
        <listener>
            <listener-class>
                org.springframework.web.context.ContextLoaderListener
            listener-class>
        listener>
        <filter>
            <filter-name>characterEncodingFilterfilter-name>
            <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
            <init-param>
                <param-name>encodingparam-name>
                <param-value>UTF-8param-value>
            init-param>
            <init-param>
                <param-name>forceEncodingparam-name>
                <param-value>trueparam-value>
            init-param>
        filter>
        <filter-mapping>
            <filter-name>characterEncodingFilterfilter-name>
            <url-pattern>/*url-pattern>
        filter-mapping>
    web-app>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44

    1.3.8 商家管理后台

    1、构建web模块 youlexuan_shop_web

    在这里插入图片描述
    与运营商管理后台的构建方式类似。

    2、修改Pom.xml (注:要加 war)

    
    <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>youlexuan_parentartifactId>
            <groupId>com.zqlgroupId>
            <version>1.0version>
        parent>
        <modelVersion>4.0.0modelVersion>
    
        <artifactId>youlexuan_shop_webartifactId>
    
        <packaging>warpackaging>
        <properties>
            <webVersion>3.0webVersion>
        properties>
        <dependencies>
            
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-contextartifactId>
            dependency>
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-beansartifactId>
            dependency>
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-webmvcartifactId>
            dependency>
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-jdbcartifactId>
            dependency>
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-aspectsartifactId>
            dependency>
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-jmsartifactId>
            dependency>
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-context-supportartifactId>
            dependency>
            <dependency>
                <groupId>org.springframeworkgroupId>
                <artifactId>spring-testartifactId>
            dependency>
            
            <dependency>
                <groupId>com.alibabagroupId>
                <artifactId>dubboartifactId>
            dependency>
            <dependency>
                <groupId>org.apache.zookeepergroupId>
                <artifactId>zookeeperartifactId>
            dependency>
            <dependency>
                <groupId>org.apache.curatorgroupId>
                <artifactId>curator-recipesartifactId>
            dependency>
            <dependency>
                <groupId>junitgroupId>
                <artifactId>junitartifactId>
            dependency>
            <dependency>
                <groupId>com.alibabagroupId>
                <artifactId>fastjsonartifactId>
            dependency>
            <dependency>
                <groupId>javassistgroupId>
                <artifactId>javassistartifactId>
            dependency>
            <dependency>
                <groupId>commons-codecgroupId>
                <artifactId>commons-codecartifactId>
            dependency>
            <dependency>
                <groupId>javax.servletgroupId>
                <artifactId>servlet-apiartifactId>
                <scope>providedscope>
            dependency>
            <dependency>
                <groupId>com.zqlgroupId>
                <artifactId>youlexuan_commonartifactId>
                <version>1.0version>
            dependency>
            <dependency>
                <groupId>com.zqlgroupId>
                <artifactId>youlexuan_sellergoods_interfaceartifactId>
                <version>1.0version>
            dependency>
        dependencies>
        <build>
            <plugins>
                
                <plugin>
                    <groupId>org.apache.tomcat.mavengroupId>
                    <artifactId>tomcat7-maven-pluginartifactId>
                    <configuration>
                        <path>/path>
                        <port>9102port>
                    configuration>
                plugin>
            plugins>
        build>
    
    project>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111

    注意:定义tomcat的启动端口为9102

    3、创建springmvc配置文件

    在src/main下创建包:com.zql.shop.controller

    在src/main/resources下创建 spring/springmvc.xml

    
    <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">
    
        <context:component-scan base-package="com.zql.shop.controller"/>
        <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">
                        <array>
                            <value>WriteMapNullValuevalue>
                            <value>WriteDateUseDateFormatvalue>
                        array>
                    property>
                bean>
            mvc:message-converters>
        mvc:annotation-driven>
        
        <dubbo:application name="youlexuan_shop_web" />
        <dubbo:registry address="zookeeper://192.168.188.180:2181"/>
        <dubbo:annotation package="com.zql.shop.controller" />
    beans>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29

    4、创建web.xml

    在webapps下创建WEB-INF/web.xml ,加载spring容器

    在这里插入图片描述

    
    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
             version="4.0">
    
        <servlet>
            <servlet-name>springmvcservlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
            <init-param>
                <param-name>contextConfigLocationparam-name>
                <param-value>classpath:spring/springmvc.xmlparam-value>
            init-param>
        servlet>
        <servlet-mapping>
            <servlet-name>springmvcservlet-name>
            <url-pattern>*.dourl-pattern>
        servlet-mapping>
        <context-param>
            <param-name>contextConfigLocationparam-name>
            <param-value>classpath:spring/spring-*.xmlparam-value>
        context-param>
        <listener>
            <listener-class>
                org.springframework.web.context.ContextLoaderListener
            listener-class>
        listener>
        <filter>
            <filter-name>characterEncodingFilterfilter-name>
            <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
            <init-param>
                <param-name>encodingparam-name>
                <param-value>UTF-8param-value>
            init-param>
            <init-param>
                <param-name>forceEncodingparam-name>
                <param-value>trueparam-value>
            init-param>
        filter>
        <filter-mapping>
            <filter-name>characterEncodingFilterfilter-name>
            <url-pattern>/*url-pattern>
        filter-mapping>
    web-app>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44

    1.4 实体类与数据访问层模块

    1.4.1 生成代码

    利用反向工程 generatorSqlmapCustom 实现实体类与数据访问层代码的自动生成

    (1) 导入IDEA 进行自己对应的配置

    在这里插入图片描述

    (2) 一键生成

    在这里插入图片描述

    1.4.2 拷贝代码

    • 将com.zql.pojo包拷贝到pojo工程
    • 将com.zql.mapper 包和 resouce 下的 com.zql.mapper 文件夹拷贝到 dao 工程(拷贝时确认连同包路径一起拷贝,可能出现包路径作为资源文件路径情况,出现错误绑定失败错误)

    (3) 生成 优乐选 代码 👉🏾👉🏾点我

    在这里插入图片描述

    copy 如下位置 👇🏾👇🏾

    在这里插入图片描述

    1.4.3 修改实体类代码

    修改每个实体类,让其实现 Serializable 接口(次要,因为使用的都实现了Serializable 接口)

    二、品牌列表-后端代码

    2.1 需求分析

    完成品牌管理的后端代码,在浏览器可查询品牌的数据(json格式)

    5.2数据库表

    tb_brand 品牌表

    字段类型长度含义
    idBigint主键
    nameVarchar255品牌名称
    first_charVarchar1品牌首字母

    2.2 后端代码

    2.2.1 服务层接口

    在 youlexuan_sellergoods_interface 工程创建 BrandService 接口

    包名 :com.zql.sellergoods.service

    package com.zql.sellergoods.service;
    
    import com.zql.pojo.TbBrand;
    
    import java.util.List;
    
    /**
     * 品牌服务层接口
     * @Author:Daniel
     * @Version 1.0
     */
    public interface BrandService {
    
        /**
         * 返回全部列表
         * @return
         */
        public List<TbBrand> findAll();
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    2.2.2 服务实现类

    在 youlexuan_sellergoods_service 工程创建 BrandServiceImpl 类

    包名 com.zql.sellergoods.service.impl (应该搭建框架的时候创建了包名)

    package com.zql.sellergoods.service.impl;
    
    import com.alibaba.dubbo.config.annotation.Service;
    import com.zql.mapper.TbBrandMapper;
    import com.zql.pojo.TbBrand;
    import com.zql.sellergoods.service.BrandService;
    import org.springframework.beans.factory.annotation.Autowired;
    
    import java.util.List;
    
    /**
     * @Author:Daniel
     * @Version 1.0
     */
    
    @Service  //dubbo
    public class BrandServiceImpl implements BrandService {
        
        @Autowired
        private TbBrandMapper brandMapper;
        @Override
        public List<TbBrand> findAll() {
            
            return brandMapper.selectByExample(null);
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    2.2.3 控制层代码

    在 youlexuan_manager_web 工程创建 com.zql.sellergoods.controller 包,包下创建BrandController类 (应该搭建框架的时候创建了包名)

    package com.zql.sellergoods.controller;
    
    import com.zql.pojo.TbBrand;
    import com.zql.sellergoods.service.BrandService;
    import jdk.nashorn.internal.ir.annotations.Reference;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    import java.util.List;
    
    /**
     * 品牌controller
     * @Author:Daniel
     * @Version 1.0
     */
    @RestController   //可点击看源码了解哈哈
    @RequestMapping("/brand")
    public class BrandController {
    
        @Reference  //dubbo
        private BrandService  brandService;
        @RequestMapping("findAll")
        public List<TbBrand> findAll(){
    
            return brandService.findAll();
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28

    2.3 测试

    1. 整体安装哈哈

    在这里插入图片描述

    1. 启动 youlexuan_sellergoods_service

    在这里插入图片描述

    1. 启动youlexuan_manager_web

    在这里插入图片描述
    (1) 地址栏输入 http://192.168.188.180:8080/dubbo 查看是否有服务提供者

    在这里插入图片描述

    (2) 地址栏输入 http://localhost:9101/brand/findAll.do

    在这里插入图片描述

    (3)再次查看是否有消费者 👇🏾👇🏾

    在这里插入图片描述

    2.4 快捷启动 tomcat

    (1) 快捷启动 youlexuan_sellergoods_service
    在这里插入图片描述
    (2) 快捷启动 youlexuan_manager_web 同(1)

    在这里插入图片描述

    OK 项目架构起初成功,可以看到浏览器输出了 json 数据。 ✌✌

  • 相关阅读:
    Yuan 2.0-M32 是一个基于 Yuan 2.0 架构的双语混合专家 (MoE) 语言模型,旨在以更少的参数和计算量实现更高的准确率
    redis未授权访问漏洞
    国创证券|资源再生概念持续活跃,超越科技两连板,大地海洋等走高
    Firefox 119 正式发布
    【Leetcode】python回溯算法结果出现[[], [], []](列表深拷贝 浅拷贝问题)
    努力一周,开源一个超好用的接口Mock工具——Msw-Tools
    PHP自动执行下一页脚本
    C++ 基础:指针和引用浅谈
    基于若依ruoyi-nbcio支持flowable流程角色,同时修改流转用户为username,流程启动做大调整(二)
    创建自定义日志筛选器
  • 原文地址:https://blog.csdn.net/weixin_42171159/article/details/126146434