Solon

::sansheng-solon-plugin

</> markdown

此插件,由社区成员(peigen)贡献

<dependency>
   <groupId>com.gitee.peigenlpy</groupId>
   <artifactId>sansheng-solon-plugin</artifactId>
   <version>1.0.0-SNAPSHOT</version>
</dependency>

1、描述

三生(SanSheng):意为三生万物。 本项目使用Beetl模版开发,基于actable-solon-plugin

本项目代码简单,并配有SanSheng-Example工程,供学习使用。

2、配置示例

新建数据库 库名:actable,并在文件app.xml中配置数据库参数,如下:

actable:
  dataSource:
    schema: actable
    jdbcUrl: jdbc:mysql://localhost:3306/actable?useUnicode=true&characterEncoding=utf8&autoReconnect=true&rewriteBatchedStatements=true
    driverClassName: com.mysql.cj.jdbc.Driver
    username: root
    password: peigen
    type: "com.zaxxer.hikari.HikariDataSource"
  model:
    pack:
      - "com.gitee.peigenlpy.sansheng.example.repository.entity"

3、应用示例

写一个标注actable-solon-plugin注解的Entity类,如下:

import com.gitee.peigenlpy.actable.annotation.Column;
import com.gitee.peigenlpy.actable.annotation.Index;
import com.gitee.peigenlpy.actable.annotation.Table;
import com.gitee.peigenlpy.actable.annotation.Unique;
import com.gitee.peigenlpy.actable.constants.MySqlCharsetConstant;
import com.gitee.peigenlpy.actable.constants.MySqlEngineConstant;
import com.gitee.peigenlpy.actable.constants.MySqlTypeConstant;
import com.gitee.peigenlpy.sansheng.example.repository.entity.enums.CustomerStatus;
import lombok.*;
import lombok.experimental.Accessors;
import lombok.experimental.FieldDefaults;

/**
 * <b>(CustomerEntity)</b>
 * 客户表
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2021/8/1
 */
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@FieldDefaults(level = AccessLevel.PRIVATE)
@Accessors(chain = true)
@Table(name = "customer", comment = "客户表", charset = MySqlCharsetConstant.UTF8MB4, engine = MySqlEngineConstant.InnoDB)
@org.beetl.sql.annotation.entity.Table(name = "customer")
public class CustomerEntity extends AbstractCreateTimeEntity {
    @Column(name = "customer_id", type = MySqlTypeConstant.VARCHAR, length = 30, isNull = false, comment = "customerId")
    @Unique(value = "customerId", columns = "customer_id")
    @org.beetl.sql.annotation.entity.Column("customer_id")
    String         customerId;
    @Column(name = "status", type = MySqlTypeConstant.VARCHAR, length = 20, isNull = false,
            comment = "客户状态;INIT:初始化, QUICK_REGISTER:快速注册客户, UN_ACTIVATED:注册未激活, UN_CERT:未实名, CERT_PASS:已实名, NORMAL:正常客户, FREEZE:账户被冻结, UN_SUBSCRIBE:账户被注销")
    @Index(value = "status", columns = "status")
    @org.beetl.sql.annotation.entity.Column("status")
    CustomerStatus status;
    @Column(name = "customer_score", type = MySqlTypeConstant.BIGINT, length = 30, isNull = false, comment = "客户积分")
    @org.beetl.sql.annotation.entity.Column("customer_score")
    Long           customerScore;
    @Column(name = "mobile", type = MySqlTypeConstant.VARCHAR, length = 20, comment = "手机号")
    @Unique(value = "mobile", columns = "mobile")
    @org.beetl.sql.annotation.entity.Column("mobile")
    String         mobile;
    @Column(name = "email", type = MySqlTypeConstant.VARCHAR, length = 100, comment = "邮件")
    @org.beetl.sql.annotation.entity.Column("email")
    String         email;
    @Column(name = "permission", type = MySqlTypeConstant.JSON, comment = "客户权限")
    @org.beetl.sql.annotation.entity.Column("permission")
    String         permission;
}

写一个启动类,类似下面这个,我是放到单元测试下面的

import com.gitee.peigenlpy.sansheng.core.util.CodeGenerateAction;
import com.gitee.peigenlpy.sansheng.core.util.CodeGenerateUtil;
import com.gitee.peigenlpy.sansheng.example.repository.entity.CustomerEntity;
import org.junit.jupiter.api.Test;

/**
 * <b>(CodeGenerateUtilTest)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023/7/21
 */
public class CodeGenerateUtilTest {

    @Test
    public void genAll() {
        CodeGenerateAction action = CodeGenerateAction.all();
        CodeGenerateUtil.execute(CustomerEntity.class, action);
    }

    @Test
    public void createController() {
        CodeGenerateAction action = CodeGenerateAction.builder().createController(true).build();
        CodeGenerateUtil.execute(CustomerEntity.class, action);
    }
}

接下来会生成如下结构的代码:

manage包是后台管理的后端代码;repository是用于完善ORM操作的类,遵循Mybatis。

这些代码的生成方式在template文件夹下配置,beetl.properties是beetl模版的配置文件,遵循Beetl的配置方式。

具体的模版与生成代码的分别请参考Beetl模版和sansheng-solon-plugin中的代码