背景
最近有个小项目,需要一个管理后台,以前的由于技术层太旧了而且其它依赖比较多,不想带过来,于是想趁着新项目,试一下一些开源的业务框架.
后台管理系统相关介绍与guns的说明
jeecg,jeesite以前经常听到,去下载来看了,发现jeecg设计的过于自动了,都不太清楚怎么开发新的业务
jeesite还不错,有明显暴露的web编写,其界面和使用体验也真不错,不过其表要按其标准来设计.而且底层代码不开源
guns 比较新,也比较简单,其代码全部开源,没有上面的两个那么完善(其实还差得有点远),不过重在简单易看好修改,所以选择这个
其它还有基于spring cloud等的开源框架,考虑到我们只是刚开始,所以没去选择
guns分析与其适应性修改
现在时间是2018/12,guns的作者把其功能 拆分了多个模块依赖
管理后台的业务主要是 https://gitee.com/stylefeng/guns
底层依赖是rose-kernel https://gitee.com/stylefeng-Roses/roses-kernel
其次,是生成器模块https://gitee.com/stylefeng/guns-generator
其代码比较 手动,均需要自己编写.
适应性修改
如果在使用过程中,希望项目能更扩展性好一些,可以把其 依赖的 底层业务模块加到 系统中.
新建一个空的maven project
把下面几个项目引进来
采用maven的父子模块方式,把各依赖均加到自己的服务中
drwxr-xr-x 1 aguns 1049089 0 12月 14 14:26 guns/
drwxr-xr-x 1 aguns 1049089 0 12月 14 14:26 guns-generator/
drwxr-xr-x 1 aguns 1049089 0 12月 14 14:26 kernel-core/
drwxr-xr-x 1 aguns 1049089 0 12月 14 14:26 kernel-model/
-rw-r--r-- 1 aguns 1049089 6840 12月 14 10:11 pom.
/pom. 中,这一部分是copyhttps://gitee.com/stylefeng-Roses/roses-kernel.git 中的/pom. ,有所修改,
<parent>
<groupId>org.spring work.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
</parent>
<groupId>com.mytest.manage</groupId>
<artifactId>backguns</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>kernel-model</module>
<module>kernel-core</module>
<module>guns</module>
</modules>
<properties>
<java.version>1.8</java.version>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
<mp.springboot.version>2.3</mp.springboot.version>
<fastjson.version>1.2.47</fastjson.version>
<druid.version>1.1.10</druid.version>
<kaptcha.version>2.3.2</kaptcha.version>
<jwt.version>0.9.1</jwt.version>
<hutool.version>4.1.2</hutool.version>
<spring.boot.admin>2.0.1</spring.boot.admin>
<lombok.versin>1.18.0</lombok.versin>
</properties>
<dependencyManagement>
<dependencies>
<!--spring cloud-->
<dependency>
<groupId>org.spring work.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--数据库-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mp.springboot.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>${mp.springboot.version}</version>
</dependency>
<!--工具类-->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-core</artifactId>
<version>${hutool.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<!--验证码-->
<dependency>
<groupId>com.github.penggle</groupId>
<artifactId>kaptcha</artifactId>
<version>${kaptcha.version}</version>
</dependency>
<!--jwt-->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>${jwt.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.versin}</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>${spring.boot.admin}</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
<version>${spring.boot.admin}</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>${spring.boot.admin}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*. </include>
</includes>
</resource>
</resources>
</build>
kernel-model/pom.
<parent>
<artifactId>backguns</artifactId>
<groupId>com.mytest.manage</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>kernel-model</artifactId>
<packaging>jar</packaging>
<version>v201812</version>
<de ion>一些通用实体,枚举,异常等规范</de ion>
<dependencies>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!--注意provided-->
<dependency>
<groupId>org.spring work</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spring work.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
kernel-core/pom.
<parent>
<artifactId>backguns</artifactId>
<groupId>com.mytest.manage</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>kernel-core</artifactId>
<version>v201812</version>
<packaging>jar</packaging>
<de ion>核心包,被其他模块引用</de ion>
<dependencies>
<dependency>
<groupId>com.mytest.manage</groupId>
<artifactId>kernel-model</artifactId>
<version>v201812</version>
</dependency>
<!--工具类-->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-core</artifactId>
</dependency>
<!--数据库-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
</dependency>
<dependency>
<groupId>org.spring work.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<!--工具类-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<!--aop-->
<dependency>
<groupId>org.spring work.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!--feign远程调用,**注意可选**-->
<dependency>
<groupId>org.spring work.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<scope>provided</scope>
</dependency>
<!--缓存,**注意可选**-->
<dependency>
<groupId>org.spring work.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<scope>provided</scope>
</dependency>
<!--web ,**注意可选**-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spring work.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>provided</scope>
</dependency>
<!--缓存,**注意可选**-->
<dependency>
<groupId>org.spring work.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spring work.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
guns-generator/pom.
<groupId>cn.stylefeng.guns</groupId>
<artifactId>guns-generator</artifactId>
<version>v201812</version>
<packaging>jar</packaging>
<name>guns-generator</name>
<de ion>代码生成器</de ion>
<parent>
<groupId>org.spring work.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.mytest.manage</groupId>
<artifactId>kernel-core</artifactId>
<version>201812</version>
</dependency>
<dependency>
<groupId>com.ibeetl</groupId>
<artifactId>beetl</artifactId>
<version>2.9.3</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generate</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.spring work.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*. </include>
</includes>
</resource>
</resources>
</build>
guns/pom.
<parent>
<artifactId>backguns</artifactId>
<groupId>com.mytest.manage</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>cn.stylefeng.guns</groupId>
<artifactId>guns</artifactId>
<version>1.0.0</version>
<name>guns-admin</name>
<de ion>mytest后台(guns 的spring boot版本)</de ion>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<shiro.version>1.4.0</shiro.version>
<kaptcha.version>2.3.2</kaptcha.version>
<ehcache.version>3.3.1</ehcache.version>
<beetl.version>2.9.3</beetl.version>
<swagger.version>2.9.2</swagger.version>
<ehcache.core.version>2.6.11</ehcache.core.version>
<mysql-connector-java.version>8.0.11</mysql-connector-java.version>
<jwt.version>0.9.0</jwt.version>
</properties>
<dependencies>
<dependency>
<groupId>cn.stylefeng.guns</groupId>
<artifactId>guns-generator</artifactId>
<version>v201812</version>
</dependency>
<!--核心组件-->
<dependency>
<groupId>com.mytest.manage</groupId>
<artifactId>kernel-core</artifactId>
<version>v201812</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector-java.version}</version>
</dependency>
<!--spring boot依赖-->
<dependency>
<groupId>org.spring work.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.spring work.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.spring work.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.spring work.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.spring work.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spring work.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<!--shiro依赖和缓存-->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>${shiro.version}</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>${shiro.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-ehcache</artifactId>
<version>${shiro.version}</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>${ehcache.version}</version>
</dependency>
<!--验证码-->
<dependency>
<groupId>com.github.penggle</groupId>
<artifactId>kaptcha</artifactId>
<version>${kaptcha.version}</version>
</dependency>
<!--beetl模板引擎-->
<dependency>
<groupId>com.ibeetl</groupId>
<artifactId>beetl</artifactId>
<version>${beetl.version}</version>
</dependency>
<!--swagger-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
</dependency>
<!--jwt token-->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>${jwt.version}</version>
</dependency>
<!--需要分布式session的话需要放开注释-->
<!--<dependency>-->
<!--<groupId>org.spring work.session</groupId>-->
<!--<artifactId>spring-session-data-redis</artifactId>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.spring work.boot</groupId>-->
<!--<artifactId>spring-boot-starter-data-redis</artifactId>-->
<!--</dependency>-->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.spring work.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork><!-- 如果没有该项配置,肯呢个devtools不会起作用,即应用不会restart -->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<delimiters>
<delimiter>@</delimiter>
</delimiters>
<useDefaultDelimiters>false</useDefaultDelimiters>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/webapp</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*. </include>
</includes>
</resource>
</resources>
</build>
<profiles>
<profile>
<id>local</id>
<properties>
<spring.active>local</spring.active>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>dev</id>
<properties>
<spring.active>dev</spring.active>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<spring.active>test</spring.active>
</properties>
</profile>
<profile>
<id>produce</id>
<properties>
<spring.active>produce</spring.active>
</properties>
</profile>
</profiles>
怎么使用生成代码的工具?
代码生成菜单:
随后,在生成的代码中找到 TUser.sql,里面有增加到菜单 的语句(建议 )
,或者,用下面的方式:增加到菜单,
再分配菜单到角色管理员中,然后重启刷新即可
双数据库?
guns已经有相应的数据源处理了,但我都调不通,后来发现有个要修改的地方:
如果在做多数据源的时候,有下面这样的配置,则spring会自己生成一个bean名为datasource的对象,
spring:
datasource:
url: jdbc:mysql://127.0.0.1:3306/guns?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT
username: root
password: root
filters: wall,mergeStat
解决:
可以把上面的spring: 去掉改成自定义的,即把默认数据源给去掉!!
biz:
datasource:
url: jdbc:mysql://127.0.0.1:3306/guns?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT
username: root
password: root
filters: wall,mergeStat
当然,相应的properties配置也要改!!!
@Bean
@ConfigurationProperties(prefix = \"biz.datasource\")
public DruidProperties druidProperties() {
return new DruidProperties();
}
原因解释:
在com.baomidou.mybatisplus.spring.boot.starter.MybatisPlusAutoConfiguration中有如下代码:
@Bean
@ConditionalOnMissingBean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
MybatisSqlSessionFactoryBean factory = new MybatisSqlSessionFactoryBean();
由于使用了spring默认的配置,则这个datasource不是我们想要的 DynamicDataSource
如果自己配置的DynamicDataSource对象也叫datasource,则自己的对象不会执行导致后续请求总是会走 默认数据源!!!
说明
guns是比较新的业务架子,也比较简单而且全部开源,
感谢作者的开源,非常便利,希望能给这个项目多多贡献
附项目链接
https://gitee.com/stylefeng/guns
继续阅读与本文标签相同的文章
-
走,我们一起让改变发生
2026-05-18栏目: 教程
-
互联网娱乐的风口浪尖下,老虎游戏机该如何选择?
2026-05-18栏目: 教程
-
道屹道:即时聊天APP开发 符合当前的时代潮流
2026-05-18栏目: 教程
-
微软前CEO鲍尔默,会成为下一个库克吗?商业模式错误
2026-05-18栏目: 教程
-
加速4G、5G网络演进 全“芯”展锐出新招
2026-05-18栏目: 教程
