spring万能模板
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
barney 0226e7e68d modify README.md 8 months ago
.mvn/wrapper init 8 months ago
doc init 8 months ago
sql init 8 months ago
src init 8 months ago
.DS_Store init 8 months ago
.gitignore init 8 months ago
Dockerfile init 8 months ago
README.md modify README.md 8 months ago
mvnw init 8 months ago
mvnw.cmd init 8 months ago
pom.xml init 8 months ago

README.md

SpringBoot 项目初始模板

基于 Java SpringBoot 的项目初始模板,整合了常用框架和主流业务的示例代码。

只需 1 分钟即可完成内容网站的后端!!!大家还可以在此基础上快速开发自己的项目。

模板特点

主流框架 & 特性

  • Spring Boot 2.7.2
  • Spring MVC
  • MyBatis + MyBatis Plus 数据访问(开启分页)
  • Spring Boot 调试工具和项目处理器
  • Spring AOP 切面编程
  • Spring Scheduler 定时任务
  • Spring 事务注解

数据存储

  • MySQL 数据库
  • Redis 内存数据库
  • Elasticsearch 搜索引擎
  • 腾讯云 COS 对象存储

工具类

  • Easy Excel 表格处理
  • Hutool 工具库
  • Gson 解析库
  • Apache Commons Lang3 工具类
  • Lombok 注解

业务特性

  • Spring Session Redis 分布式登录
  • 全局请求响应拦截器(记录日志)
  • 全局异常处理器
  • 自定义错误码
  • 封装通用响应类
  • Swagger + Knife4j 接口文档
  • 自定义权限注解 + 全局校验
  • 全局跨域处理
  • 长整数丢失精度解决
  • 多环境配置

业务功能

  • 提供示例 SQL(用户、帖子、帖子点赞、帖子收藏表)
  • 用户登录、注册、注销、更新、检索、权限管理
  • 帖子创建、删除、编辑、更新、数据库检索、ES 灵活检索
  • 帖子点赞、取消点赞
  • 帖子收藏、取消收藏、检索已收藏帖子
  • 帖子全量同步 ES、增量同步 ES 定时任务
  • 支持微信开放平台登录
  • 支持微信公众号订阅、收发消息、设置菜单
  • 支持分业务的文件上传

单元测试

  • JUnit5 单元测试
  • 示例单元测试类

架构设计

  • 合理分层

MySQL 数据库

1)修改 application.yml 的数据库配置为你自己的:

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/my_db
    username: root
    password: 123456

2)执行 sql/create_table.sql 中的数据库语句,自动创建库表

3)启动项目,访问 http://localhost:8101/api/doc.html 即可打开接口文档,不需要写前端就能在线调试接口了~

Redis 分布式登录

1)修改 application.yml 的 Redis 配置为你自己的:

spring:
  redis:
    database: 1
    host: localhost
    port: 6379
    timeout: 5000
    password: 123456

2)修改 application.yml 中的 session 存储方式:

spring:
  session:
    store-type: redis

3)移除 MainApplication 类开头 @SpringBootApplication 注解内的 exclude 参数:

修改前:

@SpringBootApplication(exclude = {RedisAutoConfiguration.class})

修改后:

@SpringBootApplication

Elasticsearch 搜索引擎

1)修改 application.yml 的 Elasticsearch 配置为你自己的:

spring:
  elasticsearch:
    uris: http://localhost:9200
    username: root
    password: 123456

2)复制 sql/post_es_mapping.json 文件中的内容,通过调用 Elasticsearch 的接口或者 Kibana Dev Tools 来创建索引(相当于数据库建表)

PUT post_v1
{
 参数见 sql/post_es_mapping.json 文件
}

这步不会操作的话需要补充下 Elasticsearch 的知识,或者自行百度一下~

3)开启同步任务,将数据库的帖子同步到 Elasticsearch

找到 job 目录下的 FullSyncPostToEsIncSyncPostToEs 文件,取消掉 @Component 注解的注释,再次执行程序即可触发同步:

// todo 取消注释开启任务
//@Component