Git Product home page Git Product logo

imitation-sql's Introduction

imitation-sql

介绍

java代码中像写编写SQL语句一样,编写代码

软件架构

软件架构说明

使用说明

1.基本用法
//1.select
SqlBuilder<UserEntity> sqlBuilder = new SqlBuilder<>(UserEntity.class);
String sql = sqlBuilder.select().buildSql();

//2.select where
SqlBuilder<UserEntity> sqlBuilder = new SqlBuilder<>(UserEntity.class);
String sql = sqlBuilder.select().where(o -> o.and(UserEntity::getUserName, "11").and(UserEntity::getPassword, "1234")).buildSql();

//3.select Where group by order by
SqlBuilder<UserEntity> sqlBuilder = new SqlBuilder<>(UserEntity.class);
String sql = sqlBuilder.select().where(o -> o.and(UserEntity::getUserName, "11").and(UserEntity::getPassword, "1234")).groupBy(o -> o.groupBy(UserEntity::getUserName)).orderBy(o -> o.asc(UserEntity::getUserName)).buildSql();

//4.select  join where
SqlBuilder<UserEntity> sqlBuilder = new SqlBuilder<>(UserEntity.class);
String sql = sqlBuilder.select().leftJoin(o -> o.eq(UserRoleEntity.class, UserEntity::getId, UserRoleEntity::getUserId))
        .innerJoin(o -> o.eq(UserRoleEntity.class, RoleEntity.class, UserRoleEntity::getRoleId, RoleEntity::getId))
        .where(o -> o.and(UserEntity::getUserName, "11").and(UserRoleEntity.class, UserRoleEntity::getRoleId, "1")).buildSql();
        
2.自动生成的api接口
使用方法
在实体类上,继承BaseEntity,添加@EnableAutoApi注解即可

示例
@Setter
@Getter
@TableName("t_user")
@EnableAutoApi
public class UserEntity extends BaseEntity {

    private String userName;

    private String password;
}

自动生成的接口

#{entityName} 代表具体的实体类名称

接口名称 接口地址 接口方法 Content-Type
详情 /#{entityName} /detail/{id} GET
分页查询 /#{entityName}/page POST application/json
列表查询 /#{entityName}/list POST application/json
新增 /#{entityName} POST application/json
修改 /#{entityName} POST application/json
删除 /#{entityName} DELETE
批量删除 /#{entityName}/batchDelete DELETE
物理删除 /#{entityName}/physicalDelete DELETE
批量物理删除 /#{entityName}/physicalBatchDelete DELETE

接口返回值格式

{
  <!-- 返回码 0-成功;-1失败 -->
  "code": "0", 
  "msg": "成功",
  "data": {} //具体返回值
}
详情

入参

路径中填入id

出参

{
  "code": "0", 		//返回码 0-成功;-1失败
  "msg": "成功",
  "data": {
      "id":1,
       ...			//其他的字段数据
  } 
}
分页查询

入参

{
    "pageSize": 10,			//每页显示条数,默认 10
    "pageNum": 1			//当前的页数
    ... 					//查询的参数
}

出参

{
    "code": null,
    "msg": null,
    "data": {
        "records": [		//具体数据
            {
                "id": 1,
				 ...		//其他的字段数据
            }
        ],
        "total": 4,			//总条数
        "size": 10,			//每页显示条数,默认 10
        "current": 1,		//当前的页数
        "pages": 1			//总页数
    }
}
列表查询

入参

{
    ... 					//查询的参数
}

出参

{
    "code": null,
    "msg": null,
    "data": [				//具体数据
        {
            "id": 1,
             ...			//其他的字段数据
        }
    ]
}
新增

入参

{
    ... 					//新增字段
}

出参

{
    "code": null,
    "msg": null,
    "data": {
        "id": 1,
         ...			//其他的字段数据
    }
}
修改

入参

{
    "id":1,					//主键id
    ... 					//新增字段
}

出参

{
    "code": null,
    "msg": null,
    "data": true			//修改成功返回true,失败返回false
}
删除

入参

id=11

出参

{
    "code": null,
    "msg": null,
    "data": true			//删除成功返回true,失败返回false
}
批量删除

入参

ids=1,2,3,4

出参

{
    "code": null,
    "msg": null,
    "data": true			//删除成功返回true,失败返回false
}
物理删除

入参

id=11

出参

{
    "code": null,
    "msg": null,
    "data": true			//删除成功返回true,失败返回false
}
批量物理删除

入参

ids=1,2,3,4

出参

{
    "code": null,
    "msg": null,
    "data": true			//删除成功返回true,失败返回false
}

imitation-sql's People

Contributors

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