Code Monkey home page Code Monkey logo

xjx79 / x-boot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from exrick/xboot

0.0 1.0 0.0 758 KB

基于Spring Boot 2.x的前后端分离开发平台X-Boot 前台:Vue+iView 后台:Spring Boot 2.x/Spring Security/JWT/Spring Data JPA+Mybatis-Plus/Redis/Elasticsearch 分布式限流/同步锁/验证码/SnowFlake雪花算法ID自增 动态权限管理 代码生成 日志记录

Home Page: http://xboot.exrick.cn

License: GNU General Public License v3.0

Java 100.00%

x-boot's Introduction

X-Boot

AUR GitHub stars GitHub forks

作者大四作品 能力经验有限 如有错误欢迎指正 期待您的捐赠支持!

在线Demo

http://xboot.exrick.cn

前台为基于Vue+iView的独立项目请跳转至 x-boot-front 项目仓库查看

项目简介

  • 代码拥有详细注释 学习与实战的不错选择
  • 核心使用目前最新 SpringBoot 2.0.1.RELEASE
  • JPA + Mybatis-Plus任意切换
    • 项目持久层默认推荐使用JPA,更简单易上手,且OOP首先应满足面向对象的要求,而不是面向数据库。复杂业务逻辑需联表查询时可选择Mybatis-Plus写sql
  • AOP操作日志记录方式任意切换
    • 默认使用数据库记录记录,可配置切换使用Elasticseach记录,使用Spring-Data-Elasticsearch简化开发
  • 极简代码生成
    • 只需输入实体类名即可生成三层代码,自动创建数据库表
  • 为什么要前后端分离
    • 都什么时代了还在用JQuery?

分支说明

  • master:基于Redis的‘JWT’ (待提交)
  • jwt:基于JWT,由于刷新token机制较麻烦,作者不推荐(待提交)
  • oauth2:基于OAuth2协议(待开发)

前端所用技术

  • Vue 2.5.x、iView、iview-admin、iview-area、Vuex、Vue Router、ES6、webpack、axios、echarts、cookie等
  • 前台为基于Vue+iView的独立项目请跳转至 x-boot-front 项目仓库查看

后端所用技术

各框架依赖版本皆使用目前最新版本

项目运行部署

  • 安装依赖并启动:RedisElasticsearch(当配置使用ES记录日志时需要)
  • Maven安装和在IDEA中配置
  • 使用IDEA(破解/免费注册) 导入该Maven项目
  • 修改配置文件 application.yml 相应配置,其中有详细注释
  • MySQL数据库新建 xboot 数据库,配置文件已开启ddl自动生成表结构但无初始数据,请记得运行导入sql文件
  • 配置第三方服务
    • Mob接口 现在需要注册申请后使用 在 cn.exrick.common.utils.IpInfoUtil 中修改填入你的AppKey
    • 七牛云对象存储 cn.exrick.common.utils.QiniuUtil 中修改填入你的配置
  • 启动运行 XbootApplication.java 默认端口8888 访问接口文档 http://localhost:8888/swagger-ui.html 说明启动成功 管理员账密admin|123456
  • 前台页面请启动基于Vue的 xboot-front 项目,并修改其接口代理配置

学习记录(更新中)

1.Spring Boot 2.x 区别总结

2.Spring Security整合JWT

3.Spring Security动态数据库权限管理

开发指南及相关技术栈说明

  • 项目使用 Lombok 插件简化开发,请自行在编译器中安装,不安装会报错但不影响运行,常用注解说明:

    • @Data:自动生成get、set等方法
    • @Slf4j:日志打印可直接使用log.info()等
  • 配置文件可使用Jasypt加密,可到 cn.exrick.xboot.common 包中找到 JasyptUtil 工具类生成加解密结果

# 配置文件加密key
jasypt:
  encryptor:
    password: xboot

spring:
  # 数据源
  datasource:
    # Jasypt加密 可到common-utils中找到JasyptUtil加解密工具类生成加密结果 格式为ENC(加密结果)
    password: ENC(F4B0s6u9xcDw3V+P0qC4CA==)
  • 操作日志使用ES或数据库记录配置 注解使用 @SystemLog(description="操作日志名称")
xboot:
  # 日志记录方式 true使用Elasticsearch记录 false记录至数据库中
  logRecord:
    es: false
  • 接口相关

    • 为方便前台配置代理,所有接口建议以统一路径例如“/xboot”开头
    • 登录成功后前台请在返回的result字段中保存token

    • 之后的请求中请在header或参数中添加该token即可

  • 分布式限流(基于Redis令牌桶算法)

    • 全局限流
    xboot:
      # 全局限流
      rateLimit:
        enable: true
        # 每1秒内
        timeout: 1000
        # 总限制100个请求
        limit: 100
    • 指定方法限流注解
    @RateLimiter(limit = 1, timeout = 5000)
    • 支持多维度IP、uid等限流 详见代码
  • 分布式同步锁(基于Redis)

    @Autowired
    private RedisDistributedLockTemplate lockTemplate;

    lockTemplate.execute("订单流水号", 5000, new Callback() {
        @Override
        public Object onGetLock() throws InterruptedException {
            //TODO 获得锁后要做的事
            log.info("生成订单流水号");
            return null;
        }
    
        @Override
        public Object onTimeout() throws InterruptedException {
            //TODO 获得锁超时后要做的事
            return null;
        }
    });
  • 后台开发代码生成

    • 代码生成方法在 cn.exrick.xboot.generator 包中的 XbootGenerator.java 工具类,修改好生成类配置后运行主函数main方法即可生成三层相关代码,别忘了在实体类中添加相关字段,运行项目后将自动生成数据库表
  • 增删改查(CRUD)

    • JPA与Mybatis-Plus随意切换

    • 不想写sql?Spring Data JPA 了解一下

      具体x-boot增删改文档示例

    • 复杂业务逻辑JPA联表太蛋疼?MyBatis-Plus 这就不用了解了吧

    • JPA与MybatisPlus同时使用时需注意实体类注解区别,更多请见官方文档,常用注解区别:

    //表名
    JPA: @Table(name = "t_user")
    MP:  @TableName("t_user")
    //排除非表字段
    JPA: @Transient
    MP:  @TableField(exist=false)
  • Spring缓存注解

    @CacheConfig(cacheNames = "user")
    public interface UserService extends XbootBaseService<User,String> {
        @Cacheable(key = "#username")
        User findByUsername(String username);
    }
    • 删除刷新注解 @CacheEvict(key = "#u.username") 手动删除刷新缓存时注意key为:user::username
  • Spring Security官方推荐权限管理:@PreAuthorize("hasRole('ADMIN')")

  • Spring定时:@Scheduled(cron="cron表达式")

  • Spring异步:@Async

等自行了解

作者其他项目推荐

技术疑问交流

捐赠

x-boot's People

Contributors

exrick avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.