Java 程序员平台后台管理-java

再见前端!纯 Java 撸个后台管理系统,这框架用起来贼爽

2021-05-11  本文已影响0人  程序花生

一个管理系统,往往需要后端+前端一起实现。单表CRUD操作往往都差不多,我们可以使用代码生成器来实现。有时候我们的管理系统只需要一些简单的CRUD页面,有没有什么框架能做到不写前端代码,纯Java撸个管理系统呢?这里推荐一个全栈类框架Erupt,希望对大家有所帮助!

Erupt简介

Erupt是一个低代码全栈类框架,它使用Java 注解动态生成页面以及增、删、改、查、权限控制等后台功能。零前端代码、零CURD、自动建表,仅需一个类文件 + 简洁的注解配置,快速开发企业级后台管理系统。

基本使用

我们首先来波实战,以商品品牌管理为例,来熟悉下Erupt结合SpringBoot的基本使用!

SpringBoot整合Erupt

由于Erupt原生支持SpringBoot,所以整合还是很方便的!

<properties>
    <erupt.version>1.6.13</erupt.version>
</properties>
<dependencies>
    <!--用户权限管理-->
    <dependency>
        <groupId>xyz.erupt</groupId>
        <artifactId>erupt-upms</artifactId>
        <version>${erupt.version}</version>
    </dependency>
    <!--接口数据安全-->
    <dependency>
        <groupId>xyz.erupt</groupId>
        <artifactId>erupt-security</artifactId>
        <version>${erupt.version}</version>
    </dependency>
    <!--后台WEB界面-->
    <dependency>
        <groupId>xyz.erupt</groupId>
        <artifactId>erupt-web</artifactId>
        <version>${erupt.version}</version>
    </dependency>
    <!--Mysql数据库驱动-->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.15</version>
    </dependency>
</dependencies>
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/erupt?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
    username: root
    password: root
  jpa:
    show-sql: true
    generate-ddl: true
    database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
    database: mysql
/**
 * Created by macro on 2021/4/13.
 */
@Configuration
@ComponentScan({"xyz.erupt","com.macro.mall.tiny"})
@EntityScan({"xyz.erupt","com.macro.mall.tiny"})
@EruptScan({"xyz.erupt","com.macro.mall.tiny"})
public class EruptConfig {
}

实现单表 CRUD

使用核心注解@Erupt和@EruptField定义一个实体类即可快速完成CRUD操作,让我们以商品品牌管理为例试试吧。

@Erupt(name = "商品品牌")
@Table(name = "pms_brand")
@Entity
public class PmsBrand {

    @Id
    @GeneratedValue(generator = "generator")
    @GenericGenerator(name = "generator", strategy = "native")
    @Column(name = "id")
    @EruptField
    private Long id;

    @EruptField(
            views = @View(title = "品牌名称"),
            edit = @Edit(title = "品牌名称",notNull=true,search = @Search(vague = true))
    )
    private String name;

    @EruptField(
            views = @View(title = "品牌首字母"),
            edit = @Edit(title = "品牌首字母",notNull=true)
    )
    private String firstLetter;

    @EruptField(
            views = @View(title = "品牌LOGO"),
            edit = @Edit(title = "品牌LOGO", type = EditType.ATTACHMENT,
                    attachmentType = @AttachmentType(type = AttachmentType.Type.IMAGE))
    )
    private String logo;

    @EruptField(
            views = @View(title = "品牌专区大图"),
            edit = @Edit(title = "品牌专区大图", type = EditType.ATTACHMENT,
                    attachmentType = @AttachmentType(type = AttachmentType.Type.IMAGE))
    )
    private String bigPic;

    @EruptField(
            views = @View(title = "品牌故事"),
            edit = @Edit(title = "品牌故事")
    )
    private String brandStory;

    @EruptField(
            views = @View(title = "排序"),
            edit = @Edit(title = "排序")
    )
    private Integer sort;

    @EruptField(
            views = @View(title = "是否显示"),
            edit = @Edit(title = "是否显示")
    )
    private Boolean showStatus;

    @EruptField(
            views = @View(title = "品牌制造商"),
            edit = @Edit(title = "品牌制造商")
    )
    private Boolean factoryStatus;

    private Integer productCount;

    private Integer productCommentCount;

}

核心注解说明

几个Erupt的核心注解,对照PmsBrand中的代码学习即可!

@Erupt

@EruptField

@View

@Edit

扩展模块

当然Erupt的功能远不止于此,还集成了很多实用的系统功能,包括定时任务、代码生成器、系统监控及NoSQL支持等。

定时任务erupt-job

通过定时任务功能,我们可以在代码中定义好定时任务,然后在图形化界面中操作任务,有点之前讲过的PowerJob 的感觉!

<!--定时任务erupt-job-->
<dependency>
    <groupId>xyz.erupt</groupId>
    <artifactId>erupt-job</artifactId>
    <version>${erupt.version}</version>
</dependency>
spring:
  mail:
    username: xxxxxx@qq.com
    password: 123456
    host: smtp.exmail.qq.com
    port: 465
    properties:
      mail.smtp.ssl.auth: true
      mail.smtp.ssl.enable: true
      mail.smtp.ssl.required: true
/**
 * Created by macro on 2021/4/13.
 */
@Service
@Slf4j
public class JobHandlerImpl implements EruptJobHandler {
    @Override
    public String exec(String code, String param) throws Exception {
        log.info("定时任务已经执行,code:{},param:{}",code,param);
        return "success";
    }
}

代码生成器erupt-generator

如果你觉得手写实体类比较麻烦的话,还可以用用Erupt中的代码生成器。

<!-- 代码生成器 erupt-generator -->
<dependency>
    <groupId>xyz.erupt</groupId>
    <artifactId>erupt-generator</artifactId>
    <version>${erupt.version}</version>
</dependency>

系统监控erupt-monitor

通过使用Erupt的系统监控功能,我们可以查看服务器的配置、Redis的缓存使用情况和在线用户信息。

<!--服务器监控 erupt-monitor-->
<dependency>
    <groupId>xyz.erupt</groupId>
    <artifactId>erupt-monitor</artifactId>
    <version>${erupt.version}</version>
</dependency>
spring:
  redis:
    host: localhost # Redis服务器地址
    database: 1 # Redis数据库索引(默认为0)
    port: 6379 # Redis服务器连接端口
    password: 123456 # Redis服务器连接密码(默认为空)
    timeout: 3000ms # 连接超时时间
erupt:
  # 开启redis方式存储session,默认false,开启后需在配置文件中添加redis配置
  redisSession: true

NoSQL数据源erupt-mongodb

Erupt支持多种数据源,包括:MySQL、Oracle、PostgreSQL、H2,甚至支持 MongoDB。下面我们来体验下MongoDB的支持功能。

<!--NoSQL数据源 erupt-mongodb-->
<dependency>
    <groupId>xyz.erupt</groupId>
    <artifactId>erupt-mongodb</artifactId>
    <version>${erupt.version}</version>
</dependency>
spring:
  data:
    mongodb:
      host: localhost # mongodb的连接地址
      port: 27017 # mongodb的连接端口号
      database: erupt # mongodb的连接的数据库
/**
 * Created by macro on 2021/4/13.
 */
@EruptDataProcessor(EruptMongodbImpl.MONGODB_PROCESS)  //此注解表示使用MongoDB来存储数据
@Document(collection = "product")
@Erupt(
        name = "商品管理",
        orderBy = "sort"
)
public class PmsProduct {
    @Id
    @EruptField
    private String id;

    @EruptField(
            views = @View(title = "商品名称", sortable = true),
            edit = @Edit(title = "商品名称", search = @Search(vague = true))
    )
    private String name;

    @EruptField(
            views = @View(title = "副标题", sortable = true),
            edit = @Edit(title = "副标题", search = @Search(vague = true))
    )
    private String subTitle;

    @EruptField(
            views = @View(title = "价格", sortable = true),
            edit = @Edit(title = "价格")
    )
    private Double price;

    @EruptField(
            views = @View(title = "商品图片"),
            edit = @Edit(title = "商品图片", type = EditType.ATTACHMENT,
                    attachmentType = @AttachmentType(type = AttachmentType.Type.IMAGE))
    )
    private String pic;

    @EruptField(
            views = @View(title = "状态", sortable = true),
            edit = @Edit(title = "状态",
                    boolType = @BoolType(trueText = "上架", falseText = "下架"),
                    search = @Search)
    )
    private Boolean publishStatus;

    @EruptField(
            views = @View(title = "创建时间", sortable = true),
            edit = @Edit(title = "创建时间", search = @Search(vague = true))
    )
    private Date createTime;
}
@EruptDataProcessor(EruptMongodbImpl.MONGODB_PROCESS)  //此注解表示使用MongoDB来存储数据
@Document(collection = "product")
@Erupt(
        name = "商品管理",
        orderBy = "sort"
)
public class PmsProduct {
    //...省略若干代码
}

在线接口开发erupt-magic-api

最后再介绍一个神奇的功能,直接通过UI界面来开发接口,无需定义Controller、Service、Dao、Mapper、XML、VO等Java对象!

<!--在线接口开发 erupt-magic-api-->
<dependency>
    <groupId>xyz.erupt</groupId>
    <artifactId>erupt-magic-api</artifactId>
    <version>${erupt.version}</version>
</dependency>
erupt:
  # 设置具体哪些包被jackson消息转化而不是gson
  jacksonHttpMessageConvertersPackages:
    - org.ssssssss

magic-api:
  web: /magic/web
  # 接口配置文件存放路径
  resource.location: D:/erupt/magic-script
var sql = "select * from pms_brand";    
return db.select(sql);

总结

如果你的需求是搭建一个业务并不复杂的后台管理系统,Erupt是一个很好的选择!它能让你不写前端代码!但是如果你的需求方对界面有很多要求,而你的业务逻辑又比较复杂的话那就要自己实现前端了!

上一篇下一篇

猜你喜欢

热点阅读