01_商城项目设计与工程搭建

01_DERAM商城项目设计与工程搭建

1.商城项目分析与设计

  • 附件:商城项目设计.pdf

2.技术选型和开发环境

2.1 技术选型
  • Spring、SpringMVC、Mybatis

  • JSP、JSTL、jQuery、EasyUI、KindEditor(富文本编辑器)

  • Redis(缓存服务器,单点登录,购物车)

  • Solr(搜索)

  • dubbo(分布式服务框架)HttpClient(HTTP 协议访问客户端)

  • ActiveMQ(消息队列)

  • Quartz(定时任务)

  • FastDFS(图片服务器)

  • FreeMarker(网页静态化)

  • Nginx(反向代理服务器)

  • MyCat(数据库中间件)

5.5 开发环境

  • IntelliJ IDEA 2019.2.2 x64

  • Maven 3.3.9

  • Tomcat 7.0.92(Maven Tomcat Plugin)

  • JDK 1.8

  • Mysql 5.7

  • Dubbo 2.5.3

  • Nginx 1.8.0

  • Redis 3.0.0

  • ActiveMQ 5.13.0

  • Win10 操作系统

  • GIT(版本管理)


3.工程搭建

3.1 使用Maven搭建工程
  • 好处

    • 管理jar包
    • 管理工程之间的依赖关系
    • 自动打包
    • 统一版本控制
  • 工程分析的结构(根据功能模块会搭建很多工程,先搭建后台管理工程)

    • Maven的常见打包方式

      • jar:java工程
      • war:web工程
      • pom:聚合工程(可以包含子工程)
    • 结构

      • dream_parent:dream商城的父工程,pom,管理整个项目的统一的版本号,所有项目都继承它
        • dream_common:通用的工具类的工程,通用的类型pojo,工具util,jar
        • dream_manager:后台管理服务层工程。pom
          • dream_manager_pojo:后台管理的pojo类型 jar
          • dream_manager_dao:dao层,为service提供接口 jar
          • dream_manager_interface:接口工程 jar
          • dream_manager_service:提供服务的业务层工程 war(为了方便发布服务)
        • dream_manager_web:后台管理的表现层,调用所有关于后台操作的业务层服务war

      结构不要弄错!!!

3.2 工程搭建
  • dream_parent
    • 新建一个空project,取名为dream
      01_商城项目设计与工程搭建_第1张图片01_商城项目设计与工程搭建_第2张图片
      01_商城项目设计与工程搭建_第3张图片

    • new->module->Maven
      01_商城项目设计与工程搭建_第4张图片
      01_商城项目设计与工程搭建_第5张图片

    • 填写名称:dream_parent
      01_商城项目设计与工程搭建_第6张图片

    • next->finish

    • 编辑pom.xml,更改打包方式为pom
      在这里插入图片描述

    • 添加jar包依赖和版本控制–pom.xml

      
      <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.dreamgroupId>
          <artifactId>dream_parentartifactId>
          <version>1.0-SNAPSHOTversion>
          <packaging>pompackaging>
      
          
          <properties>
              <junit.version>4.12junit.version>
              <spring.version>4.2.4.RELEASEspring.version>
              <mybatis.version>3.2.8mybatis.version>
              <mybatis.spring.version>1.2.2mybatis.spring.version>
              <mybatis.paginator.version>1.2.15mybatis.paginator.version>
              <mysql.version>5.1.32mysql.version>
              <slf4j.version>1.6.4slf4j.version>
              <jackson.version>2.4.2jackson.version>
              <druid.version>1.0.9druid.version>
              <httpclient.version>4.3.5httpclient.version>
              <jstl.version>1.2jstl.version>
              <servlet-api.version>2.5servlet-api.version>
              <jsp-api.version>2.0jsp-api.version>
              <joda-time.version>2.5joda-time.version>
              <commons-lang3.version>3.3.2commons-lang3.version>
              <commons-io.version>1.3.2commons-io.version>
              <commons-net.version>3.3commons-net.version>
              <pagehelper.version>3.4.2-fixpagehelper.version>
              <jsqlparser.version>0.9.1jsqlparser.version>
              <commons-fileupload.version>1.3.1commons-fileupload.version>
              <jedis.version>2.7.2jedis.version>
              <solrj.version>4.10.3solrj.version>
              <dubbo.version>2.5.3dubbo.version>
              <zookeeper.version>3.4.7zookeeper.version>
              <zkclient.version>0.1zkclient.version>
              <activemq.version>5.13.0activemq.version>
              <freemarker.version>2.3.23freemarker.version>
              <quartz.version>2.2.2quartz.version>
          properties>
          <dependencyManagement>
              <dependencies> 
                  <dependency>
                      <groupId>joda-timegroupId>
                      <artifactId>joda-timeartifactId>
                      <version>${joda-time.version}version>
                  dependency> 
                  <dependency>
                      <groupId>org.apache.commonsgroupId>
                      <artifactId>commons-lang3artifactId>
                      <version>${commons-lang3.version}version>
                  dependency>
                  <dependency>
                      <groupId>commons-iogroupId>
                      <artifactId>commons-ioartifactId>
                      <version>${commons-io.version}version>
                  dependency>
                  <dependency>
                      <groupId>commons-netgroupId>
                      <artifactId>commons-netartifactId>
                      <version>${commons-net.version}version>
                  dependency> 
                  <dependency>
                      <groupId>com.fasterxml.jackson.coregroupId>
                      <artifactId>jackson-databindartifactId>
                      <version>${jackson.version}version>
                  dependency> 
                  <dependency>
                      <groupId>org.apache.httpcomponentsgroupId>
                      <artifactId>httpclientartifactId>
                      <version>${httpclient.version}version>
                  dependency> 
                  <dependency>
                      <groupId>org.quartz-schedulergroupId>
                      <artifactId>quartzartifactId>
                      <version>${quartz.version}version>
                  dependency> 
                  <dependency>
                      <groupId>junitgroupId>
                      <artifactId>junitartifactId>
                      <version>${junit.version}version>
                      <scope>testscope>
                  dependency> 
                  <dependency>
                      <groupId>org.slf4jgroupId>
                      <artifactId>slf4j-log4j12artifactId>
                      <version>${slf4j.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>com.github.miemiedevgroupId>
                      <artifactId>mybatis-paginatorartifactId>
                      <version>${mybatis.paginator.version}version>
                  dependency>
                  <dependency>
                      <groupId>com.github.pagehelpergroupId>
                      <artifactId>pagehelperartifactId>
                      <version>${pagehelper.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.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>jstlgroupId>
                      <artifactId>jstlartifactId>
                      <version>${jstl.version}version>
                  dependency>
                  <dependency>
                      <groupId>javax.servletgroupId>
                      <artifactId>servlet-apiartifactId>
                      <version>${servlet-api.version}version>
                      <scope>providedscope>
                  dependency>
                  <dependency>
                      <groupId>javax.servletgroupId>
                      <artifactId>jsp-apiartifactId>
                      <version>${jsp-api.version}version>
                      <scope>providedscope>
                  dependency> 
                  <dependency>
                      <groupId>commons-fileuploadgroupId>
                      <artifactId>commons-fileuploadartifactId>
                      <version>${commons-fileupload.version}version>
                  dependency> 
                  <dependency>
                      <groupId>redis.clientsgroupId>
                      <artifactId>jedisartifactId>
                      <version>${jedis.version}version>
                  dependency> 
                  <dependency>
                      <groupId>org.apache.solrgroupId>
                      <artifactId>solr-solrjartifactId>
                      <version>${solrj.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>com.github.sgroschupfgroupId>
                      <artifactId>zkclientartifactId>
                      <version>${zkclient.version}version>
                  dependency>
                  <dependency>
                      <groupId>org.apache.activemqgroupId>
                      <artifactId>activemq-allartifactId>
                      <version>${activemq.version}version>
                  dependency>
                  <dependency>
                      <groupId>org.freemarkergroupId>
                      <artifactId>freemarkerartifactId>
                      <version>${freemarker.version}version>
                  dependency>
              dependencies>
          dependencyManagement>
          <build>
              <finalName>${project.artifactId}finalName>
              <plugins>
                  
                  <plugin>
                      <groupId>org.apache.maven.pluginsgroupId>
                      <artifactId>maven-resources-pluginartifactId>
                      <version>2.7version>
                      <configuration>
                          <encoding>UTF-8encoding>
                      configuration>
                  plugin> 
                  <plugin>
                      <groupId>org.apache.maven.pluginsgroupId>
                      <artifactId>maven-compiler-pluginartifactId>
                      <version>3.2version>
                      <configuration>
                          <source>1.8source>
                          <target>1.8target>
                          <encoding>UTF-8encoding>
                      configuration>
                  plugin>
              plugins>
              <pluginManagement>
                  <plugins> 
                      <plugin>
                          <groupId>org.apache.tomcat.mavengroupId>
                          <artifactId>tomcat7-maven-pluginartifactId>
                          <version>2.2version>
                      plugin> 
                      <plugin>
                          <groupId>org.apache.maven.pluginsgroupId>
                          <artifactId>maven-surefire-pluginartifactId>
                          <version>2.12.4version>
                      plugin>
                  plugins>
              pluginManagement>
          build>
      project>
      
    • 打包安装一下:把当前的parent项目安装maven的本地仓库中,其他的项目就可以进行依赖了
      01_商城项目设计与工程搭建_第7张图片

  • dream_common
    • 继承_parent,但是目录不在 _parent下

    • 右键parent工程->new->module
      01_商城项目设计与工程搭建_第8张图片

    • maven->next
      01_商城项目设计与工程搭建_第9张图片

    • 更改文件root
      01_商城项目设计与工程搭建_第10张图片

    • 添加打包jar
      01_商城项目设计与工程搭建_第11张图片

    • 添加依赖

      
      <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>dream_parentartifactId>
              <groupId>com.dreamgroupId>
              <version>1.0-SNAPSHOTversion>
              <relativePath>../dream_parent/pom.xmlrelativePath>
          parent>
          <modelVersion>4.0.0modelVersion>
      
          <artifactId>dream_commonartifactId>
          <packaging>jarpackaging>
          
          <dependencies> 
              <dependency>
                  <groupId>joda-timegroupId>
                  <artifactId>joda-timeartifactId>
              dependency> 
              <dependency>
                  <groupId>org.apache.commonsgroupId>
                  <artifactId>commons-lang3artifactId>
              dependency>
              <dependency>
                  <groupId>commons-iogroupId> 
                  <artifactId>commons-ioartifactId>
              dependency>
              <dependency>
                  <groupId>commons-netgroupId>
                  <artifactId>commons-netartifactId>
              dependency> 
              <dependency>
                  <groupId>com.fasterxml.jackson.coregroupId>
                  <artifactId>jackson-databindartifactId>
              dependency> 
              <dependency>
                  <groupId>org.apache.httpcomponentsgroupId>
                  <artifactId>httpclientartifactId>
              dependency> 
              <dependency>
                  <groupId>org.quartz-schedulergroupId>
                  <artifactId>quartzartifactId>
              dependency> 
              <dependency>
                  <groupId>junitgroupId>
                  <artifactId>junitartifactId>
              dependency> 
              <dependency>
                  <groupId>org.slf4jgroupId>
                  <artifactId>slf4j-log4j12artifactId>
              dependency>
          dependencies>
      
      project>
      
    • 安装common

  • dream_manager
    • 后台管理项目的父工程,pom,依赖common

    • 跟common过程一样

    • pom.xml

      
      <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>dream_parentartifactId>
              <groupId>com.dreamgroupId>
              <version>1.0-SNAPSHOTversion>
              <relativePath>../dream_parent/pom.xmlrelativePath>
          parent>
          <modelVersion>4.0.0modelVersion>
      
          <artifactId>dream_managerartifactId>
          <packaging>pompackaging>
          <dependencies>
              
              <dependency>
                  <groupId>com.dreamgroupId>
                  <artifactId>dream_commonartifactId>
                  <version>1.0-SNAPSHOTversion>
              dependency>
          dependencies>
      project>
      
  • dream_manager_pojo
    • 实体类工程,jar,继承manager,而且作为manager的子目录存在

    • 右键manager->new->module->maven->next
      01_商城项目设计与工程搭建_第12张图片

    • 两个next,查看目录
      01_商城项目设计与工程搭建_第13张图片

    • pom.xml:暂时不需要任何依赖

      
      <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>dream_managerartifactId>
              <groupId>com.dreamgroupId>
              <version>1.0-SNAPSHOTversion>
          parent>
          <modelVersion>4.0.0modelVersion>
      
          <artifactId>dream_manager_pojoartifactId>
          <packaging>jarpackaging>
      
      project>
      
  • dream_manager_dao

    • 构建过程跟pojo一样

    • pom.xml

      
      <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>dream_managerartifactId>
              <groupId>com.dreamgroupId>
              <version>1.0-SNAPSHOTversion>
          parent>
          <modelVersion>4.0.0modelVersion>
      
          <artifactId>dream_manager_daoartifactId>
          <packaging>jarpackaging>
      
          
          <dependencies>
              <dependency>
                  <groupId>com.dreamgroupId>
                  <artifactId>dream_manager_pojoartifactId>
                  <version>1.0-SNAPSHOTversion>
              dependency> 
              <dependency>
                  <groupId>org.mybatisgroupId>
                  <artifactId>mybatisartifactId>
              dependency>
              <dependency>
                  <groupId>org.mybatisgroupId>
                  <artifactId>mybatis-springartifactId>
              dependency>
              <dependency>
                  <groupId>com.github.miemiedevgroupId>
                  <artifactId>mybatis-paginatorartifactId>
              dependency>
              <dependency>
                  <groupId>com.github.pagehelpergroupId>
                  <artifactId>pagehelperartifactId>
              dependency> 
              <dependency>
                  <groupId>mysqlgroupId>
                  <artifactId>mysql-connector-javaartifactId>
              dependency>
              
              <dependency>
                  <groupId>com.alibabagroupId>
                  <artifactId>druidartifactId>
              dependency>
          dependencies>
      project>
      
  • dream_manager_interface
    • 跟pojo和dao一样

    • pom.xml

      
      <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>dream_managerartifactId>
              <groupId>com.dreamgroupId>
              <version>1.0-SNAPSHOTversion>
          parent>
          <modelVersion>4.0.0modelVersion>
      
          <artifactId>dream_manager_interfaceartifactId>
          <packaging>jarpackaging>
      
          <dependencies>
              <dependency>
                  <groupId>com.dreamgroupId>
                  <artifactId>dream_manager_pojoartifactId>
                  <version>1.0-SNAPSHOTversion>
              dependency>
          dependencies>
      project>
      
  • dream_manager_service
    • 业务层,给其他工程提供服务,为了便捷发布服务, 打包成war

    • 右键manager->new->module->maven->选webapp的骨架(maven项目会根据估计搭建项目结构)
      01_商城项目设计与工程搭建_第14张图片

    • 后面都一样,查看目录结构
      01_商城项目设计与工程搭建_第15张图片

    • 更改为继承manager
      01_商城项目设计与工程搭建_第16张图片
      01_商城项目设计与工程搭建_第17张图片

    • pom.xml添加依赖

      
      
      <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>dream_managerartifactId>
              <groupId>com.dreamgroupId>
              <version>1.0-SNAPSHOTversion>
          parent>
          <modelVersion>4.0.0modelVersion>
          <artifactId>dream_manager_serviceartifactId>
          <packaging>warpackaging>
          
          <dependencies> 
              <dependency>
                  <groupId>com.dreamgroupId>
                  <artifactId>dream_manager_daoartifactId>
                  <version>1.0-SNAPSHOTversion>
              dependency> 
              <dependency>
                  <groupId>com.dreamgroupId>
                  <artifactId>dream_manager_interfaceartifactId>
                  <version>1.0-SNAPSHOTversion>
              dependency>  
              <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>
          dependencies>
      project>
      
  • dream_manager_web
    • 继承parent,多个后台管理项目的表现层,war

    • 跟manager_service一样的骨架

      
      
      <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>dream_parentartifactId>
              <groupId>com.dreamgroupId>
              <version>1.0-SNAPSHOTversion>
              <relativePath>../dream_parent/pom.xmlrelativePath>
          parent>
          <modelVersion>4.0.0modelVersion>
          <artifactId>dream_manager_webartifactId>
          <version>1.0-SNAPSHOTversion>
          <packaging>warpackaging>
          <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>jstlgroupId>
                  <artifactId>jstlartifactId>
              dependency>
              <dependency>
                  <groupId>javax.servletgroupId>
                  <artifactId>servlet-apiartifactId>
                  <scope>providedscope>
              dependency>
              <dependency>
                  <groupId>javax.servletgroupId>
                  <artifactId>jsp-apiartifactId>
                  <scope>providedscope>
              dependency> 
              <dependency>
                  <groupId>commons-fileuploadgroupId>
                  <artifactId>commons-fileuploadartifactId>
              dependency>
          dependencies>
      project>
      
3.3 启动工程
  • 先启动manager

    • 添加tomcat插件
      01_商城项目设计与工程搭建_第18张图片

    • 配置maven启动
      在这里插入图片描述
      01_商城项目设计与工程搭建_第19张图片 01_商城项目设计与工程搭建_第20张图片

    • 启动查看
      01_商城项目设计与工程搭建_第21张图片

  • 启动web工程

    • 添加tomcat,端口号设置为8080

          
          <build>
              <plugins>
                  <plugin>
                      <groupId>org.apache.tomcat.mavengroupId>
                      <artifactId>tomcat7-maven-pluginartifactId>
                      <configuration>
                          <port>8080port>
                          <path>/path>
                      configuration>
                  plugin>
              plugins>
          build>
      
    • 配置maven启动
      01_商城项目设计与工程搭建_第22张图片

    • 启动测试
      01_商城项目设计与工程搭建_第23张图片

3.4 项目目录

01_商城项目设计与工程搭建_第24张图片


4.SSM整合

4.1 搭建商城项目的数据库环境
  • 新建一个数据库dream

  • 运行sql文件

    • 右键数据库->运行sql文件->选择dream.sql
      01_商城项目设计与工程搭建_第25张图片
4.2 使用MyBatis-逆向工程生成pojo和mapper文件,拷贝到pojo和dao下
  • 在MyBatis的配置文件中,修改连接的数据库,生成的数据的包,和指定的数据表
    01_商城项目设计与工程搭建_第26张图片

  • SOA的架构是需要pojo在项目中进行传输,需要对象流,把对象进行序列化,所有的pojo都需要实现序列化接口

    • 在MyBaits逆向工程生成时,指定需要实现序列化接口

      
      <plugin type="org.mybatis.generator.plugins.SerializablePlugin" />
      

      在这里插入图片描述

  • 把pojo拷贝到_pojo下,把mapper拷贝到 _dao下

4.3 配置dao层和service层
  • 在_service下新建java和resources
    01_商城项目设计与工程搭建_第27张图片

  • 在resources下新建3个资源文件夹

    • mybatis

      • 进行MyBatis的配置SqlMapConfig.xml

        
        
        <configuration>
        	
        configuration>
        
    • spring

      • applilcationContext-dao.xml:dao层的配置

        
        <beans xmlns="http://www.springframework.org/schema/beans"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:context="http://www.springframework.org/schema/context"
               xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
        
          
          <context:property-placeholder location="classpath:properties/db.properties"/>
        
          
          <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
                destroy-method="close">
            <property name="driverClassName" value="${jdbc.driver}">property>
            <property name="username" value="${jdbc.user}">property>
            <property name="password" value="${jdbc.password}">property>
            <property name="url" value="${jdbc.url}">property>
            
            <property name="initialSize" value="${initialSize}" />
            
            <property name="maxActive" value="${maxActive}" />
          bean>
          
          <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
            
            <property name="dataSource" ref="dataSource">property>
            
            <property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml">property>
          bean>
        
        
          
          <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            
            <property name="basePackage" value="com.dream.mapper" />
          bean>
        beans>
        
      • applilcationContext-service.xml:业务层的配置

        
        <beans xmlns="http://www.springframework.org/schema/beans"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:context="http://www.springframework.org/schema/context"
               xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans.xsd
               http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context.xsd">
          <context:component-scan base-package="com.dream.service"/>
        beans>
        
      • applilcationContext-truns.xml:事务管理的配置

        
        <beans xmlns="http://www.springframework.org/schema/beans"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:tx="http://www.springframework.org/schema/tx"
               xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/tx
                 http://www.springframework.org/schema/tx/spring-tx.xsd">
        
        
          
          <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            
            <property name="dataSource" ref="dataSource">property>
          bean>
          
          <tx:annotation-driven transaction-manager="transactionManager">tx:annotation-driven>
        beans>
        
    • properties

      • 配置文件db.properties

        jdbc.driver=com.mysql.jdbc.Driver
        jdbc.url=jdbc:mysql://127.0.0.1:3306/dream?useUnicode=true&characterEncoding=UTF-8
        jdbc.user=root
        jdbc.password=123456
        
        #初始化连接数
        initialSize=10
        
        #最大连接数
        maxActive=50
        
        #最大空空闲数
        maxIdle=20
        
        #最小空闲数
        minIdle=5
        
        #最大等待时间
        maxWait=60000
        
      • log4j

        # Global logging configuration
        log4j.rootLogger=DEBUG, stdout
        # Console output...
        log4j.appender.stdout=org.apache.log4j.ConsoleAppender
        log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
        log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
        
  • web.xml

    
    
    <web-app version="2.4"
             xmlns="http://java.sun.com/xml/ns/j2ee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    
      
      <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>
    
    
  • 目录
    01_商城项目设计与工程搭建_第28张图片

4.4 配置_web
  • 在main下,新建resources和java

  • 在resources下导入log4j和springmvc

    • spring

      • springmvc.xml

        
        <beans xmlns="http://www.springframework.org/schema/beans"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:context="http://www.springframework.org/schema/context"
               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/context
                http://www.springframework.org/schema/context/spring-context-4.2.xsd
        		http://www.springframework.org/schema/mvc
         		http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">
        
            <context:component-scan base-package="com.dream.controller"/>
        
            
            <mvc:annotation-driven/>
            
            <mvc:default-servlet-handler/>
            
            
            <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                <property name="prefix" value="/WEB-INF/jsp/"/>
                <property name="suffix" value=".jsp"/>
            bean>
        beans>
        
  • web.xml

    
    
    <web-app version="2.4"
             xmlns="http://java.sun.com/xml/ns/j2ee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    
      <welcome-file-list>
        <welcome-file>index.jspwelcome-file>
      welcome-file-list>
    
      
      <filter>
        <filter-name>encodingFilterfilter-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>encodingFilterfilter-name>
        <url-pattern>/*url-pattern>
      filter-mapping>
      <filter-mapping>
        <filter-name>encodingFilterfilter-name>
        <url-pattern>*.jspurl-pattern>
      filter-mapping>
      
      <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>
        <load-on-startup>1load-on-startup>
      servlet>
      <servlet-mapping>
        <servlet-name>SpringMVCservlet-name>
        
        <url-pattern>/url-pattern>
      servlet-mapping>
    
    web-app>
    
    
  • 目录

  <param-value>UTF-8param-value>
      init-param>
      <init-param>
        <param-name>forceEncodingparam-name>
        <param-value>trueparam-value>
      init-param>
    filter>
    <filter-mapping>
      <filter-name>encodingFilterfilter-name>
      <url-pattern>/*url-pattern>
    filter-mapping>
    <filter-mapping>
      <filter-name>encodingFilterfilter-name>
      <url-pattern>*.jspurl-pattern>
    filter-mapping>
    
    <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>
      <load-on-startup>1load-on-startup>
    servlet>
    <servlet-mapping>
      <servlet-name>SpringMVCservlet-name>
      
      <url-pattern>/url-pattern>
    servlet-mapping>
  
  web-app>
  
  • 目录
    01_商城项目设计与工程搭建_第29张图片

你可能感兴趣的:(分布式商城系统项目实战)