- 一、创建子模块计费模块
- 二、修改pom文件并添加springboot主类
- 三、添加项目代码
- 四、创建mysql数据库
- 五、测试项目
- 创建计费
- 查询计费
- 六、热部署
一、创建子模块计费模块
- 主模块 springcloud右键新建模块,命名为cloud-provider-payment001:
- 删除App.java和AppTest.java
- 将com设置为代码根目录,在java下新建resources目录,并设置为资源根目录:
- 修改pom文件为:
springcloud com.ruizhe.springcloud 1.0-SNAPSHOT 4.0.0 cloud-provider-payment001 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-actuator org.mybatis.spring.boot mybatis-spring-boot-starter com.alibaba druid-spring-boot-starter 1.1.10 mysql mysql-connector-java org.springframework.boot spring-boot-starter-jdbc org.springframework.boot spring-boot-devtools runtime true org.projectlombok lombok true org.springframework.boot spring-boot-starter-test test
- resources资源目录下添加配置文件application.yml文件
server:
port: 8001
spring:
application:
name: cloud-payment-service
datasource:
type: com.alibaba.druid.pool.DruidDataSource # 当前数据源操作类型
driver-class-name: org.gjt.mm.mysql.Driver # mysql驱动包
url: jdbc:mysql://192.168.137.200:3306/db2019?useUnicode=true&characterEncoding=utf-8&useSSL=false
username: root
password: 123456
mybatis:
mapperLocations: classpath:mapper
@Service
public class PaymentServiceImpl implements PaymentService
{
@Resource
private PaymentDao paymentDao;
public int create(Payment payment)
{
return paymentDao.create(payment);
}
public Payment getPaymentById(Long id)
{
return paymentDao.getPaymentById(id);
}
}
package com.ruizhe.springcloud.service;
import com.ruizhe.springcloud.entities.Payment;
import org.apache.ibatis.annotations.Param;
public interface PaymentService
{
public int create(Payment payment);
public Payment getPaymentById(@Param("id") Long id);
}
mapper/PaymentMapper.xml文件:
四、创建mysql数据库insert into payment(serial) values(#{serial}); select * from payment where id=#{id};
数据库安装参考链接:docker安装mysql
创建数据库命令:
创建数据库db2019,创建表payment
CREATE TABLE `payment` ( `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'ID', `serial` varchar(200) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb3五、测试项目 创建计费 查询计费 六、热部署
实现devtool热部署,需要执行以下4步:
- pom中添加devtool pom依赖(前面提供的pom已包含)
org.springframework.boot spring-boot-devtools runtime true
- pom中添加build插件spring-boot-maven-plugin(已经在聚合工程添加)
org.springframework.boot spring-boot-maven-plugin true true
- 构建、执行、部署–>编译器 勾选自动构建项目等选项
- 设置–>高级设置 勾选自动make自动启动



