1.先建一个父项目,去掉多余的东西 只留pom文件:
pom如下:
4.0.0
pom
springboot-dao
springboot-service
springboot-web
springboot-common
org.springframework.boot
spring-boot-starter-parent
1.5.7.RELEASE
com.zhonguo
zhuboyuan-good
0.0.1-SNAPSHOT
zhuboyuan-good
Demo project for Spring Boot
UTF-8
UTF-8
1.8
1.5.7.RELEASE
1.4.7.RELEASE
1.0.0-SNAPSHOT
Dalston.SR3
1.2.9
2.0.3
5.1.45
1.1.9
2.0.0-SNAPSHOT
2.9.3
dev
true
dev
pro
pro
org.springframework.cloud
spring-cloud-starter-eureka
org.springframework.cloud
spring-cloud-starter-feign
org.projectlombok
lombok
true
org.springframework.boot
spring-boot-devtools
runtime
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-starter-logging
com.alibaba
fastjson
${fastjson.version}
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
com.zhonguo
springboot-common
${project.version}
com.zhonguo
springboot-dao
${project.version}
com.zhonguo
springboot-service
${project.version}
com.zhonguo
springboot-web
${project.version}
mysql
mysql-connector-java
${mysql.connector.version}
runtime
com.alibaba
druid-spring-boot-starter
${druid.version}
com.github.pagehelper
pagehelper-spring-boot-starter
1.2.3
tk.mybatis
mapper-spring-boot-starter
${tk.mybatis.mapper.version}
org.springframework.boot
spring-boot-starter-redis
${springboot.starter-redis.version}
org.mybatis.generator
mybatis-generator-maven-plugin
src/main/resources/autogen/generatorConfig.xml
true
true
1.3.5
mysql
mysql-connector-java
5.1.45
tk.mybatis
mapper-generator
1.0.0
2.创建子项目:
记得打上-
finish 完成!
项目架构如下:
3.在src/main/java下自己写上和其他模块一样的前缀包名:
4.idea右侧maven:
5.可能会出现子模块变灰的情况,只需要右击父项目重新导入一下变灰的pom文件即可:
6-1:pom引入依赖:
zhuboyuan-good
com.zhonguo
0.0.1-SNAPSHOT
4.0.0
springboot-dao
jar
springboot-dao
UTF-8
mysql
mysql-connector-java
//通用mapper
tk.mybatis
mapper-spring-boot-starter
com.alibaba
druid-spring-boot-starter
com.github.pagehelper
pagehelper-spring-boot-starter
6-2:properties或者yml文件 连接数据库:
logging.level.root=debug
logging.level.tk.mybatis.springboot.mapper=trace
spring.datasource.url=jdbc:mysql://ip:3306/cmp_rule_engine
spring.datasource.username=账号
spring.datasource.password=密码
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.druid.initial-size=1
spring.datasource.druid.min-idle=1
spring.datasource.druid.max-active=20
spring.datasource.druid.test-on-borrow=true
spring.datasource.druid.stat-view-servlet.allow=true
6-3:准备生生成实体,mapper和xml:
generatorConfig.xml的内容如下自己配置好路径数据库信息和要生成哪些表即可:
6-3:项目建好之后在父项目中统一编译看有无错误:
6-4:在dao项目中找到mybatis-generator:generate 点击运行即可生成数据库的相应类
7.子模块–service:
7-1:项目结构:
7-2:service的pom文件
zhuboyuan-good
com.zhonguo
0.0.1-SNAPSHOT
4.0.0
springboot-service
jar
springboot-service
UTF-8
com.zhonguo
springboot-dao
com.zhonguo
springboot-common
com.zhonguo
springboot-cache
8:子模块–web:对外提供接口:
8-1:web结构:
zhuboyuan-good
com.zhonguo
0.0.1-SNAPSHOT
4.0.0
springboot-web
jar
springboot-web
com.zhonguo
springboot-service
org.springframework.boot
spring-boot-maven-plugin
true
src/main/webapp
src/main/resources
src/main/java
**/*.xml
8-3:配置文件(properties和yml都可)配置好数据库信息和其他信息:
application.properties:
## 激活配置
##spring.profiles.active=@activatedProperties@
spring.profiles.active=dev
## 端口
server.port=8090
## 服务名称
spring.application.name=ZHUBOYUAN-GOOD
spring.mvc.static-path-pattern=/static/**
spring.mvc.favicon.enabled=false
## mapper框架配置
mybatis.mapper-locations=classpath:sqlmapper/*.xml
mapper.not-empty=false
mapper.identity=MYSQL
application-dev.properties:
## 数据库配置
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://ip:3306/cmp_rule_engine?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8
spring.datasource.username=ruleengine
spring.datasource.password=ruleengine
## Redis 配置
## Redis数据库索引(默认为0)
spring.redis.database=0
## Redis服务器地址
spring.redis.host=ip
## Redis服务器连接端口
spring.redis.port=6379
## Redis服务器连接密码(默认为空)
spring.redis.password=rosetta4rfv5TGB
## 连接池最大连接数(使用负值表示没有限制)
spring.redis.pool.max-active=8
## 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.pool.max-wait=-1
## 连接池中的最大空闲连接
spring.redis.pool.max-idle=8
## 连接池中的最小空闲连接
spring.redis.pool.min-idle=0
## 连接超时时间(毫秒)
spring.redis.timeout=3000
logging.level.com.finance.cmp.ruleEngine.dao=debug
9.主类:
package com.zhonguo.zhuboyuan.good.springboot.web;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import tk.mybatis.spring.annotation.MapperScan;
/**
* @ComponentScan注解:
* @ComponentScan注解默认就会装配标识了
* @Controller,@Service,@Repository,@Component注解的类到spring容器中
* 就可以直接用@Autowired把类注入进来使用
* @MapperScan注解:
* 扫描Mapper类的包的路径
*/
@Slf4j
@SpringBootApplication
@ComponentScan("com.zhonguo.zhuboyuan.good.*")
@MapperScan(basePackages = "com.zhonguo.zhuboyuan.good.springboot.dao.mapper")
public class ZhuboyuanGoodApplication {
public static void main(String[] args) {
SpringApplication.run(ZhuboyuanGoodApplication.class, args);
log.info("ZhuboyuanGoodApplication is success!");
}
}
10.到此 基本完成聚合项目创建:
启动:
oj8k