Giter Club home page Giter Club logo

coffee-spring-boot-builder's Introduction

概述

与spring boot完整集成的common包,约定优于配置,所有的项目的基础脚手架依赖包。

本项目主要是目标是在靠近spring技术栈的初衷下, 尽力以spring的行为方式用更少的依赖集成一些项目的日常使用工具, 以帮助我们日常的小项目更快的开发。

在使用本项目时,你应该同意以下观点:

  • 习惯约定+注解优于提供一堆工具类
  • 可扩展性优于不必要的效率优化(例如选择jackson而不是fastjson做为序列化工具)
  • restful api接口优于后端(java)模板渲染 等等...

优势

提供通用自动配置,完全零配置并提供高度扩展能力

  • 自动配置的认证框架,包含登录/鉴权功能

  • rest配置,能够正确的返回site.zido.pojo.Result封装的json,提供OriginalResponse注解以帮助返回原值。直接返回的方式可以让controller层更薄,更易于编写。

  • json配置,自动根据profile配置json序列化方式,具体表现为prod环境下,null不参与序列化,属性不匹配会失败,节省带宽,提高返回速度 ,其他环境下返回全属性以帮助更好的提示前端各种属性

  • 全局异常自动捕捉并返回Result结果。业务异常务必继承CommonBussinessException,给予前端更好的提示处理

  • 全局请求日志,帮助快速定位问题所在,日志示例:Before request [uri=/test3/a?x=1&y=2;client=0:0:0:0:0:0:0:1;headers={host=[localhost:8080], user-agent=[curl/7.64.1], accept=[*/*]}]

  • 定义更多的校验注解,例如:@Mobile

一些其他常用工具:分布式id生成器,分布式锁等

使用

maven 加入依赖

<dependency>
    <groupId>site.zido</groupId>
    <artifactId>coffee-spring-boot-starter</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

...

完毕

认证模块 (coffee-auth)

可实现几乎0配置的自动认证模块

请注意,必须使用spring-data-jpa作为orm框架

自带的登录功能包括:

  • 微信小程序登录(可通过openId和unionId登录,优先使用unionId)
  • 帐号密码登录
  • 手机号登录(未完成)

使用

只需要实体类实现IUser接口即可完成自动登录的配置

登录接口约定为/user/login。如需定制接口,可使用AuthEntity注解,并配置url

请注意:当有多个实体类需要登录时,必须使用AuthEntity注解标记,并配置不同的url。

扫描器进行相关登录的搜寻自动配置:

  • 如包含usernamepassword字样,会自动加入用户名密码登录功能,如需要使用其他字段, 请加入AuthColumnUsernameAuthColumnPassword注解到相关字段上。
  • 如包含wechatOpenId或者wechatUnionId字样,会自动加入微信小程序登录。如需要使用其他字段, 请加入AuthColumnWechatOpenId或者AuthColumnWechatUnionId注解到相关字段上

注解式限流 (coffee-extra)

如需启用需使用 @EnableLimiter 注解

使用场景例如:手机号发送短信验证码一分钟不能超过一次(建议时间设置比实际情况略小

在需要限流的方法上加入注解@Limiter

参数如下:

  • key: 限流的key,支持spel表达式
  • timeout: 超时时间,在超时时间内不允许同key第二次调用
  • unit: 超时时间单位

可配置扩展点

禁用自动切换json序列化

site.zido.json.auto-switch.enable=false

自动配置限流器

使用redis进行限流处理

默认key前缀为coffee:limiter:

如需要定制前缀,在application.properties配置文件中使用coffee.limiter.prefix=xxx

在需要使用限流的方法上使用@Limiter注解。 ...

待完成

TODO

  • 注解式防重放攻击解决方案

coffee-spring-boot-builder's People

Contributors

zidoshare 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.