# easy-curd-spring-boot-starter **Repository Path**: niuml/easy-curd-spring-boot-starter ## Basic Information - **Project Name**: easy-curd-spring-boot-starter - **Description**: 单表的增、删、改、查、列表引入包后直接使用 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 0 - **Created**: 2022-12-05 - **Last Updated**: 2024-05-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 组件说明 - 当前包的目的是为了减少编写一些“单表”的增删改查(curd)操作 - 现阶段只适用于 spring 环境下
主要思路: - springboot项目启动时需要指定扫描当前项目的路径,进行启动后处理 - 当前项目开始运行时,会从spring容器里面找到所有有@EasyEntity注解的类, 表明类需要由项目生成增删改查列表5个接口 - 请求到接口后,当前项目会使用地址中的参数从内存里面获取对应的类,反射出其字段、查询条件、表名等。 - 使用jdbcTemplate进行查询。 # 快速开始 ### 核心依赖 | 依赖 | 版本 | | ---------------------- |------------| | java | 1.8 | | spring-boot-starter-web | 2.7.4 | | spring-boot-starter-jdbc | 2.7.4 | | mysql-connector-java | 8.0.30 | ### 模块说明 ```lua com.niuml ├── annotation -- 需要使用的注解 ├── common -- 通用的类 ├── config -- 配置类 ├── controller -- 默认controller ├── enums -- 枚举 ├── service --实现类 └── utils -- 工具类 ``` ### 使用说明 - #### 第一步 ![img.png](images/img.png) ```lua 只需要增加如下依赖即可(需提前将本项目拉取到本地并install) com.niuml easy-curd-spring-boot-starter 0.0.1 ``` - ####第二步 ![img.png](images/img2.png) ```lua @EasyEntity 用来指定当前实体对应的数据库表名 tableName 用指定表名 urlUseName 用来指定访问当前表时使用的url 默认当前实体名 e.g:/v1/easy/curd/{attr}/info,其中attr就是urlUseName @EasyEntityId 用来指定当前实体对应表的ID主键 ``` - ####第三步 ![img.png](images/img3.png) ```lua 对spring boot启动类增加@ComponentScan注解,需要指定两个扫描, 一个是"com.niuml",这个是当前组件的包路径,需要在项目中指定扫描。 一个是当前项目的包地址,需要视情况而定。 ``` ### 示例 ####示例配置文件 ```` # server: port: 9001 spring: application: name: demo7 main: allow-bean-definition-overriding: true profiles: active: dev datasource: url: jdbc:mysql://localhost:3306/test?characterEncoding=utf-8&useUnicode=true&useSSL=false&serverTimezone=UTC driver-class-name: com.mysql.cj.jdbc.Driver username: root password: 123456 easy: entity: scan: whetherAutomaticGenerateId: false #true新增时ID为程序自动生成(雪花ID) false就自己解决 whetherLogicDelete: true # 是否为逻辑删除 true:逻辑删除 false:物理删除 # path: #要扫描的路径 TODO 暂时无用 # - 'org.niuml.auth.entity.*' #这个要指定到类的最下层 encapsulationReturn: #要返回的包装体 easy curl会使用下面的实体和属性进行返回 whetherUse: true #是否使用这个包装体,如果使用的话为true,下面的生效并不可为空 classPath: com.niuml.common.Res #使用的类全路径xx.xx.xx.Abc.class attribute: data #属性 e.g:data ```` ![img.png](images/img4.png) ![img.png](images/img5.png) ###2022-12-07 新增一个接口,用以获取可以使用当前组件的所有替换字符 ![img.png](images/img6.png) # 新增信息 ## 新增数据时,可以携带集合属性 ### e.g: http://127.0.0.1:9001/v2/easy/curd/teacher/info { "id": 1, "name": "老师1", "students": [ { "id": 1, "name": "学生1" }, { "id": 2, "name": "学生2" } ] }