Skip to content

Commit

Permalink
feat: Spring Boot 整合 Erupt 开源企业后端管理开发框架案例(官方案例)
Browse files Browse the repository at this point in the history
  • Loading branch information
GitSuperDrew committed Feb 28, 2021
1 parent 39edb2c commit e0bff68
Show file tree
Hide file tree
Showing 29 changed files with 1,293 additions and 0 deletions.
Empty file.
Empty file.
Empty file.
33 changes: 33 additions & 0 deletions springboot-erupt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
21 changes: 21 additions & 0 deletions springboot-erupt/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 erupts

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
102 changes: 102 additions & 0 deletions springboot-erupt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@

<p align="center"><img src="https://www.erupt.xyz/demo/erupt.svg" height="150" alt="logo"/></p>
<h1 align="center"> Erupt Framework &nbsp; 🚀 &nbsp; 框架演示代码 </h1>
<h3 align="center">零前端代码,几行 Java 注解,搞定后台管理系统</h3>
<h3 align="center"><a href="https://erupt.xyz" target="_blank">https://www.erupt.xyz</a></h3>

---

<p align="center">
<a href="https://www.erupt.xyz" target="_blank"><img src="https://img.shields.io/badge/Erupt-Framework-brightgreen" alt="Erupt Framework"></a>
<a href="https://www.oracle.com/technetwork/java/javase/downloads/index.html"><img src="https://img.shields.io/badge/JDK-8+-green.svg" alt="jdk 8+"></a>
<a href="./LICENSE"><img src="https://img.shields.io/badge/license-Apache%202-blue" alt="license Apache 2.0"></a>
<a href="https://gitee.com/erupt/erupt"><img src="https://gitee.com/erupt/erupt/badge/star.svg?theme=dark" alt="Gitee star"></a>
<a href="https://gitee.com/erupt/erupt"><img src="https://gitee.com/erupt/erupt/badge/fork.svg?theme=dark" alt="Gitee fork"></a>
<a href="https://github.com/erupts/erupt"><img src="https://img.shields.io/github/stars/erupts/erupt?style=social" alt="GitHub stars"></a>
<a href="https://github.com/erupts/erupt"><img src="https://img.shields.io/github/forks/erupts/erupt?style=social" alt="GitHub forks"></a>
<a href="https://github.com/erupts/erupt"><img src="https://img.shields.io/github/repo-size/erupts/erupt" alt="size"></a>
</p>

<p align="center">
<a href="https://github.com/erupts/erupt">Github 仓库</a> &nbsp; | &nbsp;
<a href="https://gitee.com/erupt/erupt">Gitee 仓库</a> &nbsp; | &nbsp;
<a href="https://www.erupt.xyz" target="_blank">官方网站</a> &nbsp; | &nbsp;
<a href="https://www.yuque.com/yuepeng/erupt/bdiq6o" target="_blank">贡献指南</a> &nbsp; | &nbsp;
<a href="https://www.erupt.xyz/demo" target="_blank">在线体验</a> &nbsp; | &nbsp;
<a href="https://www.yuque.com/yuepeng/erupt" target="_blank"><b>使用文档</b></a>
</p>

<p align="center">
QQ交流群:<a href="https://jq.qq.com/?_wv=1027&k=MCd4plZ0">821389129 🔥</a>
</p>

### 使用方法:
1. 前往 src/main/resources/application.yml 修改数据库连接配置
2. 前往 src/main/java/DemoApplication 运行main方法即可

默认用户名密码: erupt / erupt


### 将model下的类添加到菜单:

启动成功后,前往系统管理 → 菜单维护 → 新增,将已定义好的演示类添加到菜单中,填写数据如下:

| 菜单名称 | 菜单类型 | 类型值(类名) | 描述 |
| ---- | ---- | ---- | ---- |
| 入门示例 | 表格 | Simple | |
| 文章管理 | 表格 | Article | |
| 树示例 || TreeView | |
| 组件示例 | 表格 | Component | 各类组件与事件代理使用方法 |
| 复杂示例 | 表格 | Complex | 动态下拉列表与定义按钮等功能 |
| 多行操作 | 功能按钮 | ComplexBtn | 控制 Complex '多行操作'的按钮权限,状态选隐藏 |
| 自定义页面 | 模板 | erupt.html | 自定义页面 |
| 链接 | 链接 | https://www.erupt.xyz | |
| 新页面 | 新页签 | https://github.com/erupts/erupt | |


**配置项说明**
> 编码:确保唯一即可,建议是字母

### 常见问题
+ 如果图片上传失败请前往 application.yml 修改 erupt.uploadPath 配置
+ 地图组件无法使用请前往 app.js 修改 eruptSiteConfig.amapKey 的值
+ 继承HyperModel的作用,可帮助管理,创建时间,修改时间,修改人,更新人字段

### 目录说明
```lua
erupt-example
├── src
├── main.java -- 源码
└── com.example.demo -- 包名
├── ExampleApplication -- 入口类
├── dao
└── ArticleRepository -- 使用对文章对象的增删改查封装,使用方式与Mybatis-Plus大同小异,具体调用详见 ExampleApplicationTests
├── handler
├── AutoCompleteHandlerImpl -- 自动完成示例
├── ComponentDataProxy -- 事件代理代码示例
└── OperationHandlerImpl -- 操作按钮处理类
└── model
├── Article -- 文章示例
├── Complex -- 复杂示例
├── ComplexOperator -- 复杂示例按钮表单
├── Componen -- 组件示例
├── Simple -- 基本示例
└── TreeView -- 树视图
├── test.java -- 测试包
└── com.example.demo -- 包名
└── ExampleApplicationTests -- 包含调用 ArticleRepository 演示代码,直接点击运行单个方法即可
└── resources -- 配置包
├── application.yml -- 后台配置
├── tpl
├── erupt.html -- 自定义页面
└── public
├── app.css -- 前端样式
├── app.js -- 前端配置
└── home.html -- 首页样式
└── pom.xml -- 依赖配置
```


# ⚠ 一定得记住:
1. 修改数据库配置,直接启动项目,项目涉及到的MySQL数据库表将使用JPA自动生成。
108 changes: 108 additions & 0 deletions springboot-erupt/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<packaging>war</packaging>

<groupId>com.example</groupId>
<artifactId>erupt-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<description>SpringBoot 整合 Erupt 后台管理快速开发框架(Erupt官方提供的起步案例) project for Spring Boot</description>

<properties>
<java.version>1.8</java.version>
<erupt.version>1.6.5</erupt.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>

<!--用户权限管理-->
<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>
<!--任务管理模块-->
<dependency>
<groupId>xyz.erupt</groupId>
<artifactId>erupt-job</artifactId>
<version>${erupt.version}</version>
</dependency>
<!--自定义模板页面模块-->
<dependency>
<groupId>xyz.erupt</groupId>
<artifactId>erupt-tpl</artifactId>
<version>${erupt.version}</version>
</dependency>
<!--代码生成器模块-->
<dependency>
<groupId>xyz.erupt</groupId>
<artifactId>erupt-generator</artifactId>
<version>${erupt.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>nexus-aliyun</id>
<name>nexus-aliyun</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import xyz.erupt.core.annotation.EruptScan;

import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

/**
* @author drew
*/
@SpringBootApplication
@ComponentScan({"xyz.erupt", "com.example.demo"}) // ↓ xyz.erupt必须有
@EntityScan({"xyz.erupt", "com.example.demo"}) // ↓ 如果包名com.example.demo有变化
@EruptScan({"xyz.erupt", "com.example.demo"}) // → 要修改为变化后的包名
public class ExampleApplication extends SpringBootServletInitializer {

public static void main(String[] args) throws URISyntaxException, IOException {
SpringApplication.run(ExampleApplication.class, args);
System.setProperty("java.awt.headless", "false");
Desktop.getDesktop().browse(new URI("http://localhost:8080"));
System.err.println("详细使用方法,请阅读:README.md");
}

/**
* 打WAR包的配置
* @param application
* @return
*/
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(ExampleApplication.class);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.demo.controller;

import com.example.demo.dao.ArticleRepository;
import com.example.demo.model.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
* @author drew
*/
@RestController
public class TestController {

@Autowired
private ArticleRepository articleRepository;

@RequestMapping("/test")
public List<Article> testArticle() {
return articleRepository.findAll();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.demo.dao;

import com.example.demo.model.Article;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

/**
* 直接继承 JpaRepository 就有了增删改查等能力,该功能由 spring-data-jpa 提供
* 泛型说明:Article 实体类对象 Long 主键数据类型
*
* @author liyuepeng
* @date 2021/1/6 18:31
*/
public interface ArticleRepository extends JpaRepository<Article, Long> {

//方法名称必须要遵循驼峰式命名规则,findBy(关键字)+属性名称(首字母大写)+查询条件(首字母大写)
List<Article> findByTitle(String title); //根据标题查找文章

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.demo.handler;

import org.springframework.stereotype.Component;
import xyz.erupt.annotation.fun.AutoCompleteHandler;

import java.util.ArrayList;
import java.util.List;

/**
* @author liyuepeng
* @date 2020-08-14
*/
@Component // 可以使用依赖注入等操作
public class AutoCompleteHandlerImpl implements AutoCompleteHandler {

@Override
public List<Object> completeHandler(String val, String[] param) {
List<Object> list = new ArrayList<>();
for (int i = 0; i < 26; i++) {
list.add(val + " -> " + (char) (i + 64));
}
return list;
}
}
Loading

0 comments on commit e0bff68

Please sign in to comment.