1.构建微服务模块
建模块
改POM
写YML
主启动
业务类
2.编写业务类
- 前后端不分离
vue-controller-service-dao-mysql - 前后端分离
vue ------ controller-service-dao-mysql
(传给一段json字符串(200,success))
3.后往前构建
- 建sql
- entities
- 主实体
- Json封装体 CommonResult
- dao
- dao
- mapper.xml
- service
- 接口
- 实现类
- controller
- idea自带工具模拟(tools)自测通过
- 后面应该用run dashboard(工程少)
4.此时订单微服务和支付微服务调用
- 原始web
httpClient - 封装为
- restTemplate(实现两个微服务的横向调用)
(url,requestMap,ResponseBean.class)
三个参数代表请求地址,请求参数,响应后被转换的对象
- restTemplate(实现两个微服务的横向调用)
- 注意:使用restTemplate过程中
- restTemplate.postForObject(PAYMENT_URL+“/payment/create”,payment,CommonResult.class);此类调用的方法的参数在请求体中
@RequestBody Payment payment - restTemplate.getForObject(PAYMENT_URL+“/payment/get/”+id,CommonResult.class);此类调用的方法在请求头中
@PathVariable(“id”) Long id
- restTemplate.postForObject(PAYMENT_URL+“/payment/create”,payment,CommonResult.class);此类调用的方法的参数在请求体中