1.1 项目数据库设计

1.1.1 数据库表设计

3.搭建盈利宝项目架构 - 图2
图片1.png

ylb.sql

2 搭建项目结构

1.IDEA创建项目类型为empty-project

1)创建mybatis逆向工程

创建maven项目,把生成实体类,接口,mapper文件。
image.png
插件
存放在项目根目录下
3.搭建盈利宝项目架构 - 图4

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE generatorConfiguration
  3. PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
  4. "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
  5. <generatorConfiguration>
  6. <!-- 指定连接数据库的JDBC驱动包所在位置,指定到你本机的完整路径 -->
  7. <!--<classPathEntry location="D:\course\server\mysql-connector-java-5.1.49.jar"/>-->
  8. <!--
  9. <dependency>
  10. <groupId>mysql</groupId>
  11. <artifactId>mysql-connector-java</artifactId>
  12. <version>5.1.49</version>
  13. </dependency>
  14. -->
  15. <!--指定了这个依赖以上就不需要指定路径了-->
  16. <!-- 配置table表信息内容体,targetRuntime指定采用MyBatis3的版本 -->
  17. <context id="tables" targetRuntime="MyBatis3">
  18. <!-- 抑制生成注释,由于生成的注释都是英文的,可以不让它生成 -->
  19. <commentGenerator>
  20. <property name="suppressAllComments" value="true" />
  21. </commentGenerator>
  22. <!-- 配置数据库连接信息 -->
  23. <jdbcConnection driverClass="com.mysql.jdbc.Driver"
  24. connectionURL="jdbc:mysql://localhost:3306/ylb"
  25. userId="root"
  26. password="123456">
  27. </jdbcConnection>
  28. <!-- 生成model类,targetPackage指定model类的包名, targetProject指定生成的model放在eclipse的哪个工程下面-->
  29. <javaModelGenerator targetPackage="com.bjpowernode.api.model"
  30. targetProject="D:\Program\Java\Project\ylb\mapper\src\main\java">
  31. <property name="enableSubPackages" value="false" />
  32. <property name="trimStrings" value="false" />
  33. </javaModelGenerator>
  34. <!-- 生成MyBatis的Mapper.xml文件,targetPackage指定mapper.xml文件的包名, targetProject指定生成的mapper.xml放在eclipse的哪个工程下面 -->
  35. <sqlMapGenerator targetPackage="mappers" targetProject="D:\Program\Java\Project\ylb\mapper\src\main\resources">
  36. <property name="enableSubPackages" value="false" />
  37. </sqlMapGenerator>
  38. <!-- 生成MyBatis的Mapper接口类文件,targetPackage指定Mapper接口类的包名, targetProject指定生成的Mapper接口放在eclipse的哪个工程下面 -->
  39. <javaClientGenerator type="XMLMAPPER" targetPackage="com.bjpowernode.dataservice.mapper" targetProject="D:\Program\Java\Project\ylb\mapper\src\main\java">
  40. <property name="enableSubPackages" value="false" />
  41. </javaClientGenerator>
  42. <!-- 数据库表名及对应的Java模型类名 -->
  43. <table tableName="b_product_info" domainObjectName="Product"
  44. enableCountByExample="false"
  45. enableUpdateByExample="false"
  46. enableDeleteByExample="false"
  47. enableSelectByExample="false"
  48. selectByExampleQueryId="false"/>
  49. <table tableName="b_bid_info" domainObjectName="BidInfo"
  50. enableCountByExample="false"
  51. enableUpdateByExample="false"
  52. enableDeleteByExample="false"
  53. enableSelectByExample="false"
  54. selectByExampleQueryId="false"/>
  55. <table tableName="b_income_record" domainObjectName="Income"
  56. enableCountByExample="false"
  57. enableUpdateByExample="false"
  58. enableDeleteByExample="false"
  59. enableSelectByExample="false"
  60. selectByExampleQueryId="false"/>
  61. <table tableName="b_recharge_record" domainObjectName="Recharge"
  62. enableCountByExample="false"
  63. enableUpdateByExample="false"
  64. enableDeleteByExample="false"
  65. enableSelectByExample="false"
  66. selectByExampleQueryId="false"/>
  67. <table tableName="u_user" domainObjectName="SysUser"
  68. enableCountByExample="false"
  69. enableUpdateByExample="false"
  70. enableDeleteByExample="false"
  71. enableSelectByExample="false"
  72. selectByExampleQueryId="false"/>
  73. <table tableName="u_finance_account" domainObjectName="FinanceAccount"
  74. enableCountByExample="false"
  75. enableUpdateByExample="false"
  76. enableDeleteByExample="false"
  77. enableSelectByExample="false"
  78. selectByExampleQueryId="false"/>
  79. </context>
  80. </generatorConfiguration>
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>com.bjpowernode</groupId>
  5. <artifactId>mapper</artifactId>
  6. <version>1.0-SNAPSHOT</version>
  7. <packaging>jar</packaging>
  8. <name>mapper</name>
  9. <url>http://maven.apache.org</url>
  10. <properties>
  11. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  12. </properties>
  13. <dependencies>
  14. <dependency>
  15. <groupId>junit</groupId>
  16. <artifactId>junit</artifactId>
  17. <version>3.8.1</version>
  18. <scope>test</scope>
  19. </dependency>
  20. <dependency>
  21. <groupId>mysql</groupId>
  22. <artifactId>mysql-connector-java</artifactId>
  23. <version>5.1.49</version>
  24. </dependency>
  25. </dependencies>
  26. <build>
  27. <plugins>
  28. <!--mybatis代码自动生成插件-->
  29. <plugin>
  30. <groupId>org.mybatis.generator</groupId>
  31. <artifactId>mybatis-generator-maven-plugin</artifactId>
  32. <version>1.3.6</version>
  33. <configuration>
  34. <!--配置文件的位置-->
  35. <configurationFile>GeneratorMapper.xml</configurationFile>
  36. <verbose>true</verbose>
  37. <overwrite>true</overwrite>
  38. </configuration>
  39. <dependencies>
  40. <dependency>
  41. <groupId>mysql</groupId>
  42. <artifactId>mysql-connector-java</artifactId>
  43. <version>5.1.49</version>
  44. </dependency>
  45. </dependencies>
  46. </plugin>
  47. </plugins>
  48. </build>
  49. </project>

在main下面创建resources
3.搭建盈利宝项目架构 - 图5
使用插件3.搭建盈利宝项目架构 - 图6

2)创建父项目image.png

3)创建micr-api项目

image.png

4)创建micr-dataservice项目

image.png
image.png
image.png
image.png
image.png

注意:
image.png
注意看这里爆红了,我们做以下修改。
在pom.xml(dataservice)中添加以下依赖。

  1. <dependency>
  2. <groupId>com.bjpowernode</groupId>
  3. <artifactId>micr-api</artifactId>
  4. <version>1.0.0</version>
  5. </dependency>

image.png

5)添加父项目依赖

  1. <!--首先把夫项目改为springboot-->
  2. <parent>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-parent</artifactId>
  5. <version>2.6.3</version>
  6. <relativePath/> <!-- lookup parent from repository -->
  7. </parent>
  8. <!--添加依赖-->
  9. <properties>
  10. <java.version>17</java.version>
  11. <dubbo.version>2.7.8</dubbo.version>
  12. <zookeeper.version>2.7.8</zookeeper.version>
  13. <mybatis.version>2.2.2</mybatis.version>
  14. <fastjson>1.2.51</fastjson>
  15. <swagger.version>2.9.2</swagger.version>
  16. <swagger.ui.version>1.9.6</swagger.ui.version>
  17. </properties>
  18. <dependencyManagement>
  19. <dependencies>
  20. <!--声明项目使用的gav-->
  21. <!--Dubbo-->
  22. <dependency>
  23. <groupId>org.apache.dubbo</groupId>
  24. <artifactId>dubbo-spring-boot-starter</artifactId>
  25. <version>${dubbo.version}</version>
  26. </dependency>
  27. <!--Zookeeper-->
  28. <dependency>
  29. <groupId>org.apache.dubbo</groupId>
  30. <artifactId>dubbo-dependencies-zookeeper</artifactId>
  31. <version>${zookeeper.version}</version>
  32. <type>pom</type>
  33. <exclusions>
  34. <exclusion>
  35. <artifactId>slf4j-log4j12</artifactId>
  36. <groupId>org.slf4j</groupId>
  37. </exclusion>
  38. </exclusions>
  39. </dependency>
  40. <!--MyBatis-->
  41. <dependency>
  42. <groupId>org.mybatis.spring.boot</groupId>
  43. <artifactId>mybatis-spring-boot-starter</artifactId>
  44. <version>${mybatis.version}</version>
  45. </dependency>
  46. <!--Fastjson-->
  47. <dependency>
  48. <groupId>com.alibaba</groupId>
  49. <artifactId>fastjson</artifactId>
  50. <version>${fastjson}</version>
  51. </dependency>
  52. <!--Swagger-->
  53. <dependency>
  54. <groupId>io.springfox</groupId>
  55. <artifactId>springfox-swagger2</artifactId>
  56. <version>${swagger.version}</version>
  57. </dependency>
  58. <dependency>
  59. <groupId>io.springfox</groupId>
  60. <artifactId>springfox-swagger-ui</artifactId>
  61. <version>${swagger.version}</version>
  62. </dependency>
  63. <dependency>
  64. <groupId>com.github.xiaoymin</groupId>
  65. <artifactId>swagger-bootstrap-ui</artifactId>
  66. <version>${swagger.ui.version}</version>
  67. </dependency>
  68. </dependencies>
  69. </dependencyManagement>
  70. <!--添加插件-->
  71. <build>
  72. <plugins>
  73. <!-- 编译插件 -->
  74. <plugin>
  75. <artifactId>maven-compiler-plugin</artifactId>
  76. <!-- 插件的版本 -->
  77. <version>3.5.1</version>
  78. <!-- 编译级别 -->
  79. <configuration>
  80. <source>1.8</source>
  81. <target>1.8</target>
  82. <!-- 编码格式 -->
  83. <encoding>UTF-8</encoding>
  84. </configuration>
  85. </plugin>
  86. </plugins>
  87. </build>

6)添加micr-dataservice项目依赖

  1. <!--把父项目改为自己的-->
  2. <parent>
  3. <groupId>com.bjpowernode</groupId>
  4. <artifactId>micr-parent</artifactId>
  5. <version>1.0.0</version>
  6. <relativePath/> <!-- lookup parent from repository -->
  7. </parent>
  8. <!--添加依賴-->
  9. <dependencies>
  10. <dependency>
  11. <groupId>com.bjpowernode</groupId>
  12. <artifactId>micr-api</artifactId>
  13. <version>1.0.0</version>
  14. </dependency>
  15. <dependency>
  16. <groupId>org.mybatis.spring.boot</groupId>
  17. <artifactId>mybatis-spring-boot-starter</artifactId>
  18. </dependency>
  19. <dependency>
  20. <groupId>mysql</groupId>
  21. <artifactId>mysql-connector-java</artifactId>
  22. <scope>runtime</scope>
  23. </dependency>
  24. <dependency>
  25. <groupId>org.springframework.boot</groupId>
  26. <artifactId>spring-boot-starter-test</artifactId>
  27. <scope>test</scope>
  28. </dependency>
  29. </dependencies>

在pom.xml(父项目)添加聚合

  1. <modules>
  2. <module>../micr-api</module>
  3. <module>../micr-dataservice</module>
  4. </modules>

application.yml核心配置文件(在resources目录下)

  1. #服务名称
  2. spring:
  3. application:
  4. name: micr-dataservice
  5. datasource:
  6. driver-class-name: com.mysql.cj.jdbc.Driver
  7. url: jdbc:mysql://localhost:3306/ylb?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8
  8. username: root
  9. password: 123456
  10. #设置mybatis
  11. mybatis:
  12. mapper-locations: classpath:/mappers/**/*.xml
  13. configuration:
  14. log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  15. map-underscore-to-camel-case: true

配置启动类 加上@MapperScan(“com.bjpowernode.dataservice.mapper”)

  1. @MapperScan("com.bjpowernode.dataservice.mapper")
  2. @SpringBootApplication
  3. public class MicrDataserviceApplication {
  4. public static void main(String[] args) {
  5. SpringApplication.run(MicrDataserviceApplication.class, args);
  6. }
  7. }

项目运行以下效果
image.png
dataservice设置Dubbo
在pom.xml(data-servcie)中添加以下依赖

  1. <!--Dubbo起步依赖-->
  2. <dependency>
  3. <groupId>org.apache.dubbo</groupId>
  4. <artifactId>dubbo-spring-boot-starter</artifactId>
  5. </dependency>
  6. <!--zookeeper-->
  7. <dependency>
  8. <groupId>org.apache.dubbo</groupId>
  9. <artifactId>dubbo-dependencies-zookeeper</artifactId>
  10. <type>pom</type>
  11. </dependency>

application中添加dubbo服务配置

  1. #Dubbo配置
  2. dubbo:
  3. registry:
  4. address: zookeeper://localhost:2181
  5. scan:
  6. base-packages: com.bjpowernode.dataservice.service
  7. provider:
  8. timeout: 50000
  9. retries: 0

在启动类上添加@EnableDubbo注解

  1. //启动Dubbo服务
  2. @EnableDubbo
  3. @MapperScan("com.bjpowernode.dataservice.mapper")
  4. @SpringBootApplication
  5. public class MicrDataserviceApplication {
  6. public static void main(String[] args) {
  7. SpringApplication.run(MicrDataserviceApplication.class, args);
  8. }
  9. }

apache-zookeeper-3.5.5-bin.tar.gz
image.png
双击图标Zookeeper启动
运行项目
image.png

7)Web服务配置

c2bca2f890bcfb3a58131e7947511960.png
ac6d5066877b1c678bc831ec9bd888b7.png
image.png

将父项目改为自己的父项目

  1. <parent>
  2. <groupId>com.bjpowernode</groupId>
  3. <artifactId>micr-parent</artifactId>
  4. <version>1.0.0</version>
  5. <relativePath/> <!-- lookup parent from repository -->
  6. </parent>

在micr-parent中添加聚合

  1. <modules>
  2. <module>../micr-api</module>
  3. <module>../micr-dataservice</module>
  4. <module>../micr-web</module>
  5. </modules>

web中的依赖项

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-web</artifactId>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.springframework.boot</groupId>
  8. <artifactId>spring-boot-starter-test</artifactId>
  9. <scope>test</scope>
  10. </dependency>
  11. <dependency>
  12. <groupId>com.bjpowernode</groupId>
  13. <artifactId>micr-api</artifactId>
  14. <version>1.0.0</version>
  15. </dependency>
  16. <dependency>
  17. <groupId>org.apache.dubbo</groupId>
  18. <artifactId>dubbo-spring-boot-starter</artifactId>
  19. </dependency>
  20. <!--zookeeper-->
  21. <dependency>
  22. <groupId>org.apache.dubbo</groupId>
  23. <artifactId>dubbo-dependencies-zookeeper</artifactId>
  24. <type>pom</type>
  25. </dependency>
  26. <!--Swagger-->
  27. <dependency>
  28. <groupId>io.springfox</groupId>
  29. <artifactId>springfox-swagger2</artifactId>
  30. </dependency>
  31. <dependency>
  32. <groupId>io.springfox</groupId>
  33. <artifactId>springfox-swagger-ui</artifactId>
  34. </dependency>
  35. <dependency>
  36. <groupId>com.github.xiaoymin</groupId>
  37. <artifactId>swagger-bootstrap-ui</artifactId>
  38. </dependency>
  39. </dependencies>
  1. spring:
  2. application:
  3. name: micro-web
  4. server:
  5. port: 8000
  6. servlet:
  7. context-path: /api
  8. encoding:
  9. enabled: true
  10. charset: utf-8
  11. force: true
  12. dubbo:
  13. registry:
  14. address: zookeeper://localhost:2181
  15. scan:
  16. base-packages: com.bjpowernode.front
  17. consumer:
  18. check: false
  19. timeout: 50000
  20. retries: 0
  1. //启用Dubbo服务
  2. @EnableDubbo
  3. @SpringBootApplication
  4. public class MicrWebApplication {
  5. public static void main(String[] args) {
  6. SpringApplication.run(MicrWebApplication.class, args);
  7. }
  8. }

点击运行是这个界面
image.png