mybatis plus java code generator,but is use go(mybatis plus 代码自动生成器,但是是用golang实现,简单便捷,开箱即用,无需安装任何其他依赖)
直接运行main
方法
访问 http://localhost:8080 进入主界面
输入sql
比如
create table "order"
(
id bigserial,
uid bigint not null,
order_id bigint not null,
order_status text,
product_num integer not null,
device_id text,
device text,
version text,
add_time timestamp(0) default now(),
update_time timestamp(0),
influhub_uid bigint,
pay_amount numeric
);
comment on table influhub_order is '订单表';
comment on column influhub_order.uid is '订单uid';
comment on column influhub_order.order_id is '订单id';
comment on column influhub_order.order_status is '订单状态(ORDER_CREATE(下单)、ORDER_CANCEL(全单取消)、ORDER_PART_CANCEL(部分取消)、ORDER_SIGN(确认收货)、ORDER_REFUND(订单退款))';
comment on column influhub_order.currency is '币种';
comment on column influhub_order.product_num is '商品数量';
comment on column influhub_order.device_id is '设备id';
comment on column influhub_order.device is '渠道(web、pc)';
comment on column influhub_order.version is '订单版本';
comment on column influhub_order.influhub_uid is 'uid';
comment on column influhub_order.pay_amount is '订单支付金额';
注意表名如果是数据库保留管关键字,需要加""
- 效果
目前仅对Postgresql进行了测试,mysql还没有测试
releases页面下载符合自己系统的二进制可执行文件
下载完解压双击运行。然后在浏览器访问http://localhost:8080
如果遇到MAC应用无法打开或提示“来自身份不明开发者”
市面上的mybatis plus
代码生成器有很多,但是都不太满足自己的要求。
在使用mybatis plus
自己会有一个规范,就是不要将mybatis plus
的Warpper
暴露到DAO
以外的层级,特别是Service
层
不然造成的后果就是Warpper
在Service
满天飞。然后有如下弊端
Service
层充满了数据查询的各种Warpper
,逻辑不够解耦,导致应该在数据层的逻辑全部暴露在Service
层Service
层的数据查询没有封装无法复用
所以我们一般使用mybatis plus
的标准用法结构是
- infra
- dao
- mapper
- OrderMapper.java
- impl
- OrderDAOImpl.java OrderDAO.java
- mapper
- entity
- OrderDO.java
- dao
具体的代码如下:
- OrderDO
@Data
public class OrderDO {
}
- OrderMapper
@Mapper
public interface OrderMapper extends BaseMapper<OrderDO> {
}
- OrderDAO
public interface OrderDAO extends IService<OrderDO> {
}
- OrderDAOImpl
@Repository
@RequiredArgsConstructor
public class OrderDAOImpl extends ServiceImpl<OrderMapper, OrderDO> implements OrderDAO {
private final InfluhubOrderMapper influhub_orderMapper;
}
在外部只使用OrderDAO
,将Wrapper
相关的逻辑都封装在DAO
中,不蔓延到Services