微服务 教程
1085个小节阅读:195.7k
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
x/**
* 订单模型
*/
public class Order implements Serializable {
// 订单id
private Long id;
// 用户id
private Long userId;
// 订单总价格
private Double prict;
// 收货人手机号
private String mobile;
// 收货人地址
private String address;
// 支付类型 1:微信 2:支付宝
private Integer pay_method;
}
xxxxxxxxxx
public interface IOrderService {
//创建订单
void createOrders(Orders orders);
//根据用户id查询订单详情
Orders findByuserId(Long userid);
}
xxxxxxxxxx
/**
* 统一返回结果集
* @param <T>
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CommonResult<T> implements Serializable {
// 返回结果编码
private Integer code;
// 返回结果描述
private String message;
// 数据
private T data;
private CommonResult(Integer code,String message){
this(code,message,null);
}
}
xxxxxxxxxx
import com.alibaba.dubbo.config.annotation.Service;
import com.itbaizhan.entity.CommonResult;
import com.itbaizhan.entity.Order;
import com.itbaizhan.service.IOrderService;
/**
* 订单功能业务层
*/
public class OrderServiceImpl implements IOrderService {
/**
* 创建订单
* @param order
* @return
*/
public CommonResult create(Orders order) {
CommonResult commonResult = new CommonResult();
// 返回结果编码
commonResult.setCode(200);
// 返回结果描述信息
commonResult.setMessage("创建成功");
return commonResult;
}
/**
* 根据用户id查询订单详情
* @param userId
* @return
*/
public CommonResult<Orders> findByUserId(Long userId) {
//TODO 模拟数据库操作
CommonResult commonResult = new CommonResult();
// 返回结果编码
commonResult.setCode(200);
// 返回结果描述信息
commonResult.setMessage("查询成功");
// 返回结果集
Orders orders = new Orders();
orders.setId(1L);
orders.setUserId(1L);
orders.setPrict(121.1);
orders.setMobile("18588888888");
orders.setAddress("北京市海淀区中关村");
orders.setPay_method(1);
commonResult.setData(order);
return commonResult;
}
}
xxxxxxxxxx
# 端口号
server.port=9090
# 1. 配置项目名称
spring.dubbo.application.name=user-service
# 2. 配置注册中心地址
spring.dubbo.registry.address=zookeeper://192.168.66.100
spring.dubbo.registry.port=2181
# 3. 指定dubbo使用的协议、端口
spring.dubbo.protocol.name=dubbo
spring.dubbo.protocol.port=20880
# 4. 指定注册到zk上超时时间,ms
spring.dubbo.registry.timeout=10000
# 5. 配置Dubbo包扫描
spring.dubbo.scan=com.itbaizhan.service
xxxxxxxxxx
import com.alibaba.dubbo.config.annotation.Service;
// 将这个类提供的方法(服务) 对外发布。将访问的地址 ip 端口
路径 注册到注册中心
//@Service //将该类的对象创建出来放到spring的IOC容器中。 bean定义
public class OrderServiceImpl implements IOrderService {
}