All Projects → skyCloud-CN → jdbcTemplatePlus

skyCloud-CN / jdbcTemplatePlus

Licence: Apache-2.0, Unknown licenses found Licenses found Apache-2.0 LICENSE Unknown license.txt
基于SpringJdbcTemplate的ORM框架,比Mybatis更方便,更简单,仅需定义Model就可支持各种SQL查询和动态SQL,不再用拼写XML文件和SQL语句,可以通过各种注解式插件扩展,目前主要支持Mysql数据库

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to jdbcTemplatePlus

Neo
Orm框架:基于ActiveRecord思想开发的至简化的java的Orm框架
Stars: ✭ 35 (+40%)
Mutual labels:  mybatis, orm-framework
MiniDao
An powerful enhanced toolkit of SpringJdbc for simplify development
Stars: ✭ 200 (+700%)
Mutual labels:  mybatis, springjdbc
Mybatis Plus
An powerful enhanced toolkit of MyBatis for simplify development
Stars: ✭ 12,132 (+48428%)
Mutual labels:  mybatis, orm-framework
GoBatis
An easy ORM tool for Golang, support MyBatis-Like XML template SQL
Stars: ✭ 113 (+352%)
Mutual labels:  mybatis, orm-framework
Springboot Learning
《Spring Boot基础教程》,2.x版本持续连载中!点击下方链接直达教程目录!
Stars: ✭ 13,916 (+55564%)
Mutual labels:  mybatis, jdbctemplate
fastquery
FastQuery(Method of fast database query) 基于Java语言. 他的使命是:简化Java操作数据层.做为一个开发者,仅仅只需要设计编写DAO接口即可,在项目初始化阶段采用ASM生成好实现类. 因此,开发代码不得不简洁而优雅.从而,大幅度提升开发效率.
Stars: ✭ 63 (+152%)
Mutual labels:  dao, orm-framework
common-datax
基于DataX的通用数据同步微服务,一个Restful接口搞定所有通用数据同步
Stars: ✭ 51 (+104%)
Mutual labels:  mybatis
spring-boot-demo
SpringBoot Demo.集成统一异常处理,Swagger,Druid,Mybatis,Redis,Mongo.
Stars: ✭ 21 (-16%)
Mutual labels:  mybatis
blog-springboot
My blog with springboot framework
Stars: ✭ 14 (-44%)
Mutual labels:  mybatis
elasticsearch-jdbc
elasticsearch-jdbc,在elasticsearch-sql的jdbc实验特性基础上完成,可使用sql和rest api的方式执行elasticsearch操作
Stars: ✭ 20 (-20%)
Mutual labels:  mybatis
multipleselect
java 结合mybatis-plus 实现非手写sql多表查询
Stars: ✭ 98 (+292%)
Mutual labels:  mybatis
mybatis-r2dbc
MyBatis R2DBC Adapter
Stars: ✭ 121 (+384%)
Mutual labels:  mybatis
robert
基于SpringCloud的企业级微服务多租户系统、多语言的脚手架, 代码组件化、高内聚低耦合,代码简介,注释丰富容易上手,该项目包括用于开发分布式应用程序服务的必要组件,支持多应用程序访问,并使开发人员可以轻松地使用Spring Cloud编程模型来开发分布式应用程序服务。
Stars: ✭ 45 (+80%)
Mutual labels:  mybatis
gd-generator
A code generator that elegantly generates mybatis ORM (mapper and xml config) and intelligently retains user-defined mapper and xml, automatically creates/synchronizes database tables, and records and prints exactly after each domain model change Database repair sql, support for the production of a variety of complex VO (View Object) objects, al…
Stars: ✭ 82 (+228%)
Mutual labels:  mybatis
Logistics-admin
SpringBoot+adminlte+maven的物流公司管理系统
Stars: ✭ 61 (+144%)
Mutual labels:  mybatis
vacomall
☀️☀️ 基于 dubbo 实现的分布式电商平台。
Stars: ✭ 42 (+68%)
Mutual labels:  mybatis
mybatis-mapper
generate SQL statements from the MyBatis3 Mapper XML file in Node.js
Stars: ✭ 64 (+156%)
Mutual labels:  mybatis
Block-Farm
A farming game built upon Ethereum platform.
Stars: ✭ 60 (+140%)
Mutual labels:  dao
javayh-platform
javayh-platform 使用Springboot2.2.6为开发脚手架,SpringCloud为云端服务框架,Nacos为注册中心、分布式配置管理中心,Oauth2协议实现统一授权,Mybatis作为持久层框架,提供了代码生成器,SQL防注入,SwaggerAPI文档,Redis 作为缓存服务等强大的功能
Stars: ✭ 32 (+28%)
Mutual labels:  mybatis
event-recommender-festa
[SI -> 오늘회, 펫프렌드 이직, 연봉 35% 상승] 내 주변지역의 이벤트와 행사를 추천해주는 서비스
Stars: ✭ 64 (+156%)
Mutual labels:  mybatis

Jdbc-Template-Plus

codebeat badge Build Status

中文版文档

Spring based Persistence Framewok for Java Web developers, By using this, you Can

  • Never write Sql
  • Develop Dao in 1 minute
  • Write Dynamic Sql just like Stream Api
  • ReflectASM inside, 3 times faster then mybatis
  • Sharding, LogicDelete and Other Functions only By One Annotation

Table Of Contents

Background

Developing Persistence Layer is really Boooooring , If you are a Java web developer, then you will definitely agree with what I said.

I have tried a log Persisitence Frame work such as Mybatis, JdbcTemplate, SpringDataJPA. They are all Excellent Framewok, but still have some shortcomings.

Mybatis support dynamic Sql but need to write lots of xml files, which cost lots of time.By using MybatisGenerator xml files can be generated but they are unmaintainable and it's annoying to have so many xml in Project

JdbcTemplate do lots of low level job for you, so you can only write SQL, but I always get runtime error tell me SQL Syntax Error when developing because a missing "," or "`" and really hard to find where is wrong.

SpringDataJPA is my favourate framework. But it is too heavy and generated SQL is a little cumbersome(For a developer at Internet company, 99% of SQL is single table query ). Dynamic sql is supported but readability is not so good

So this is why I wrote this framework

This project is just getting start, please commit Issue and STAR to support, thank you

GettingStart

I will use a example of a user table to tell you how to get start with this framework

model look like this

@Data and @ToString annotation is from Lombok, they have nothing to do with this framework

@Data
@ToString
public class User {
    private Long id;
    private String name;
    private Date updated;
    private Date created;
    private Boolean deleted;
}

1. Add Maven Dependency

currently this project is not deployed to central repo, but soon it will

<dependency>
  <groupId>io.github.skycloud-cn</groupId>
  <artifactId>jdbc-template-plus</artifactId>
  <version>1.0.0</version>
</dependency>

2. Add Annotation

add @Table and @PrimaryKey annotion like below

@Data
@ToString
@Table(tableName = "user")
public class User {
    @PrimaryKey
    private Long id;
    private String name;
    private Date updated;
    private Date created;
    private Boolean deleted;
}

3. Define Helper Class

this class is for help you write sql condition, param in Column must be exactlly same with you column name in database

public class Columns {
    public static final Column ID = new Column("id");
    public static final Column NAME = new Column("name");
    public static final Column UPDATED = new Column("updated");
    public static final Column CREATED = new Column("created");
    public static final Column DELETED = new Column("deleted");
}

4. Define DAO

Basic Method is all in BaseStorage class so No Code is need

@Service
public class UserDAO extends BaseStorage<User, Long>{

}

5.DbAndModelNamingCheck(Optional)

This step is depends on your Java Model and database column name mapping, if your Java Model property is exactly same with database column name, this step is not need.

If your database column naming by underScore like sky_cloud and Java Model property is naming by camelCase like skyCloud, you need to call method below before any SQL are executed

FastDaoConfig.setMapUnderscoreToCamelCase(true)

Otherwise, you need to tell framework you Database column name by annotation like below

@Data
@ToString
@Table(tableName = "user")
public class User {
    @PrimaryKey
    private Long id;
    private String name;
    @ColumnMap(jdbcType = JDBCType.TIMESTAMP)
    private Long updated;
    private Date created;
    @ColumnMap(column = "deleted")
    private Boolean exist;
}

@ColumnMap used in exist field tells exist field should map to column deleted

@ColumnMap used in updated field tells this field is actually TIMESTAMP type in database but not BIGINT

Usage

Method Supported by BaseStorage

    DATA selectByPrimaryKey(PRIM_KEY key);

    List<DATA> selectByPrimaryKeys(Collection<PRIM_KEY> keys);

    List<DATA> selectByPrimaryKeys(PRIM_KEY... keys);

    int insert(DATA t);

    int insertSelective(DATA t);

    int updateByPrimaryKey(DATA t);
   
    int updateByPrimaryKeySelective(DATA t);

    int deleteByPrimaryKey(PRIM_KEY t);

    List<DATA> select(QueryRequest queryRequest);

    int count(CountRequest countRequest);

    int update(UpdateRequest updateRequest);

    int delete(DeleteRequest deleteRequest);

Dynamic SQL API

here is a example for a query demand. I want to find User data created within a period of time, and also want to find user by name, these condition is optional, and I need all data are not logic deleted, data should be sort by Id, and with a page limit of 20.

QueryRequest request=Request.queryRequest()
                .beginAndCondition()
                .andOptional(NAME.like(name).matchLeft().matchRight())
                .andOptional(CREATED.gt(dateBegin).lt(dateEnd))
                .and(DELETED.equal(false))
                .endCondition()
                .addSort(ID, OrderEnum.ASC)
                .limit(20)
                .offset(0);
dao.select(request);

Plugins

Lots of useful functions is supported by plugins and can be active by only one Annotation

AutoFill

AutoFill is useful when you need to set updated,created field to db, by annotation @AutoFill these field can be autofilled when insert and updated if these property is null

@AutoFill(fillValue = AutoFillValueEnum.NOW,onOperation = {AutoFillOperation.INSERT,AutoFillOperation.UPDATE})
private Long updated;
@AutoFill(fillValue = AutoFillValueEnum.NOW,onOperation= AutoFillOperation.INSERT)
private Date created;

LogicDelete

LogicDelete can automaticly add condition logicDelete=false when query, update, count if there is no other condition about logicDelete property, and autoFill logicDeleteField to 0 or false when insert.

currently only Integer, Boolean, Long are supported

@LogicDelete
private Boolean deleted;

Sharding

execute ShardUtil.setShardSuffixOnce(suffixHere) before execute a SQL request, suffix will automaticly add to your table name in sql;

License

JdbcTemplatePlus is under the Apache 2.0 license. See the Apache License 2.0 file for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].