集成mysql数据库以及SSM框架,Mybatis-Plus框架。
项目结构:
pom.xml:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.6.RELEASE</version> <relativePath/> <!-- 不指定路径则从maven库中查找父级 --> </parent> <groupId>com.aaron</groupId> <artifactId>producer</artifactId> <version>1.0-SNAPSHOT</version> <name>producer</name> <description>Demo project for Spring Boot</description> <!-- 指定统一版本 --> <properties> <java.version>1.8</java.version> <spring-cloud.version>Greenwich.SR1</spring-cloud.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.47</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus</artifactId> <version>2.1.8</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatisplus-spring-boot-starter</artifactId> <version>1.0.5</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.57</version> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>application.yml配置文件:
#静态常量 static: ip: 127.0.0.1 eurekaport: 8016 username: root password: root #端口 server: port: 8011 #eureka注册 eureka: client: register-with-eureka: true service-url: defaultZone: http://${static.ip}:${static.eurekaport}/eureka instance: prefer-ip-address: true #设置心跳检测检测与续约时间 lease-renewal-interval-in-seconds: 30 lease-expiration-duration-in-seconds: 60 spring: #配置mysql数据库连接 datasource: url: jdbc:mysql://${static.ip}:3306/aarontest?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&failOverReadOnly=false username: ${static.username} password: ${static.password} driver-class-name: com.mysql.jdbc.Driver platform: mysql initialSize: 5 minIdle: 10 maxActive: 20 maxWait: 60000 application: #服务名称 name: producer #Mybatis映射 mybatis: mapper-locations: mappers/*Mapper.xml type-aliases-package: com.aaron.producer.Pojo configuration: #开启自动转换驼峰式 map-underscore-to-camel-case: true #Mybatis-Plus映射 mybatis-plus: mapper-locations: mappers/*Mapper.xml type-aliases-package: com.aaron.producer.Pojo configuration: #开启自动转换驼峰式 map-underscore-to-camel-case: true启动项Application:
package com.aaron.producer; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @SpringBootApplication @EnableEurekaClient @MapperScan("com.aaron.producer.Mapper") public class ProducerApplication { public static void main(String[] args){ SpringApplication.run(ProducerApplication.class,args); } }启动效果:
具体业务代码逻辑暂不做展示。