Navigation Menu

Skip to content

最佳实践

zhōuhào edited this page Jun 4, 2018 · 5 revisions

前言

hsweb的目标是提供一些后台管理中常用的功能,帮助项目的快速开发.但是hsweb不是万能的,并不是所有场景都适用.以下为推荐的使用场景:

  1. 前后分离,完全开源的后台管理项目.
  2. 细粒度权限控制,控制到按钮,数据行,数据列.
  3. 模块化,可拓展.
  4. 动态,动态查询条件,动态表单,动态数据源.....

在使用hsweb之前,如果你已经掌握以下技术栈,应该能很快上手.

  1. java8 对java8有所了解,比如java8的新特性: lambda,stream-api.
  2. maven 熟悉maven多模块项目使用.
  3. spring,spring-mvc 熟悉常用注解,类,以及使用方式.
  4. spring-boot 了解spring-boot的自动配置,配置项目以及配置方式.
  5. mybatis 熟悉mybatis的使用,以及常用配置.
  6. restful 对restful有所了解会帮助你更快对熟悉hsweb中对web api.

开始使用

hsweb并不是像常见脚手架项目一样:直接下载到本地,修改其中代码,或者在上面新增功能. hsweb是模块化的,根据你的需要,选择适合自己的模块然后maven引入,各个模块都提供了不同程度的拓展方式. 如果有新的需求可以提交issues或者pull request.

开始:

  1. 使用maven依赖的方式使用hsweb,正式版都会上传到maven中央仓库,快照版将会发布到私有仓库. 最新的正式版为: Maven Central,快照版本为:Maven metadata URI

快照版和正式版的区别: 快照版为频繁更新的版本,会不定期发布更新,即使不修改本地版本号,也会更新到最新的包,使用快照版可以体验最新的特性.而正式版相对稳定,更新频率更慢,发布到中央仓库后无需引入私服即可使用.

如果使用快照版,需要在pom.xml中引入私服:

<repositories>
 <repository> 
     <id>hsweb-nexus</id> 
     <name>Nexus Release Repository</name> 
     <url>http://nexus.hsweb.me/content/groups/public/</url> 
     <snapshots> 
         <enabled>true</enabled> 
          <updatePolicy>always</updatePolicy> <!--每次都从服务器更新最新的快照版本-->
     </snapshots> 
 </repository> 
</repositories>
  1. 引入hsweb到依赖管理
<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.hswebframework.web</groupId>
                <artifactId>hsweb-framework</artifactId>
                <version>${hsweb.framework.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
</dependencyManagement>
  1. 引入相关模块依赖

基础依赖:

<dependencies>
   <!--基本启动模块,用于系统的初始化,自动配置等操作-->
   <dependency>
      <groupId>org.hswebframework.web</groupId>
      <artifactId>hsweb-spring-boot-starter</artifactId>
   </dependency>

   <!--spring-boot 日志模块,使用slf4j+logback进行日志管理-->
   <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-logging</artifactId>
   </dependency>
   <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
   </dependency>

    <!--spring-boot-web模块,自动配置springMvc,这里不使用tomcat,而是使用undertow作为内置servlet容器-->
    <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-web</artifactId>
         <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
         </exclusions>
     </dependency>
     <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-undertow</artifactId>
     </dependency>

     <!--对spring-cache的拓展,主要是修复一个spring-cache的bug,如果开启里使用缓存,则需要引入这个依赖-->
     <dependency>
            <groupId>org.hswebframework.web</groupId>
            <artifactId>hsweb-concurrent-cache</artifactId>
            <version>${hsweb.framework.version}</version>
     </dependency>
 
</dependencies>

完整的pom配置你可以参照hsweb3-demo中的pom.xml

  1. 引入需要使用的hsweb模块

你可以在hsweb-framework 中各个模块下的README.md中获取到对应模块的使用方式.

举个🌰

TODO

  1. 权限功能使用以及拓展
  2. 单一模块的CRUD演示
  3. 模块化的CRUD演示
  4. 事件驱动的场景演示
  5. spring-cloud整合演示

常用工具类

TODO

  1. FastBeanCopier : 基于字节码的快速bean属性复制,支持复杂结构以及类型转换.
  2. EnumDict : 基于枚举的数据字典
  3. IDGenerator : ID生成器

常见问题

TODO

  1. 调用dao时,mybatis提示invalid bound statement.
  2. 打包部署到服务器后,提示找不到类: *FastBeanCopier1 .

hsweb 3.0

 3.0,全新的架构
 模块化,更细,更轻
 吸取经验,优化功能
  1. 增删改查
  2. 权限控制
  3. 访问日志
  4. 动态数据源
  5. 常用并发工具
  6. 消息封装
  7. 其他工具
Clone this wiki locally