mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
update readme
This commit is contained in:
parent
494938e5ad
commit
edaeec1506
46
readme.md
46
readme.md
@ -1,19 +1,19 @@
|
|||||||
|
|
||||||
# Mybatis-Flex 一个优雅的 Mybatis 增强框架
|
# Mybatis-Flex is an elegant Mybatis Enhancement Framework.
|
||||||
|
|
||||||
## 特征
|
## Features
|
||||||
|
|
||||||
- 1、很轻量,整个框架只依赖 Mybatis 再无其他任何第三方依赖
|
- 1、Mybatis-Flex is very lightweight, and it only depends on Mybatis and no other third-party dependencies
|
||||||
- 2、Entity 类基本的增删改查、分页查询
|
- 2、Basic CRUD operator and paging query of Entity class
|
||||||
- 3、Row 通用映射支持,可以无需实体类对数据库进行增删改查
|
- 3、Row mapping support, you can add, delete, modify and query the database without entity classes
|
||||||
- 4、支持多种数据库类型,自由通过方言持续扩展
|
- 4、Support multiple databases, and expand through dialects flexibly.
|
||||||
- 5、支持联合主键,以及不同的主键下的主键内容生成策略
|
- 5、Support combined primary keys and different primary key content generation strategies
|
||||||
- 6、极其友好的 SQL 联动查询,IDE 自动提示不再担心出错
|
- 6、Extremely friendly SQL query, IDE automatically prompts and no worries about mistakes
|
||||||
- 7、以及更多小惊喜
|
- 7、More little surprises
|
||||||
|
|
||||||
## hello world
|
## hello world
|
||||||
|
|
||||||
**实体类**
|
**Entity Class**
|
||||||
|
|
||||||
```java
|
```java
|
||||||
|
|
||||||
@ -30,17 +30,17 @@ public class Account {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**AccountMapper 类**
|
**AccountMapper Class**
|
||||||
|
|
||||||
```java
|
```java
|
||||||
public interface AccountMapper extends BaseMapper<Account> {
|
public interface AccountMapper extends BaseMapper<Account> {
|
||||||
//只需定义 Mapper 接口即可,可以无任何内容。
|
//only Mapper interface define.
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**Hello world**
|
**Hello world**
|
||||||
|
|
||||||
示例 1:查询 1 条数据
|
e.g. 1: query 1 data
|
||||||
```java
|
```java
|
||||||
class HelloWorld {
|
class HelloWorld {
|
||||||
public static void main(String... args) {
|
public static void main(String... args) {
|
||||||
@ -56,7 +56,7 @@ class HelloWorld {
|
|||||||
.start();
|
.start();
|
||||||
|
|
||||||
|
|
||||||
//示例1:查询 id=100 条数据
|
//id=100
|
||||||
Account account = MybatisFlexBootstrap.getInstance()
|
Account account = MybatisFlexBootstrap.getInstance()
|
||||||
.execute(AccountMapper.class, mapper ->
|
.execute(AccountMapper.class, mapper ->
|
||||||
mapper.selectOneById(100)
|
mapper.selectOneById(100)
|
||||||
@ -65,7 +65,7 @@ class HelloWorld {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
示例2:查询列表
|
e.g.2: query list
|
||||||
|
|
||||||
```java
|
```java
|
||||||
class HelloWorld {
|
class HelloWorld {
|
||||||
@ -81,17 +81,17 @@ class HelloWorld {
|
|||||||
.addMapper(AccountMapper.class)
|
.addMapper(AccountMapper.class)
|
||||||
.start();
|
.start();
|
||||||
|
|
||||||
//示例2:通过 QueryWrapper 构建条件查询数据列表
|
//use QueryWrapper to build query conditions
|
||||||
QueryWrapper query = QueryWrapper.create()
|
QueryWrapper query = QueryWrapper.create()
|
||||||
.select()
|
.select()
|
||||||
.from(ACCOUNT)
|
.from(ACCOUNT)
|
||||||
.where(ACCOUNT.ID.ge(100))
|
.where(ACCOUNT.ID.ge(100))
|
||||||
.and(ACCOUNT.USER_NAME.like("张").or(ACCOUNT.USER_NAME.like("李")));
|
.and(ACCOUNT.USER_NAME.like("zhang").or(ACCOUNT.USER_NAME.like("li")));
|
||||||
|
|
||||||
// 执行 SQL:
|
// execute SQL:
|
||||||
// ELECT * FROM `tb_account`
|
// ELECT * FROM `tb_account`
|
||||||
// WHERE `tb_account`.`id` >= 100
|
// WHERE `tb_account`.`id` >= 100
|
||||||
// AND (`tb_account`.`user_name` LIKE '%张%' OR `tb_account`.`user_name` LIKE '%李%' )
|
// AND (`tb_account`.`user_name` LIKE '%zhang%' OR `tb_account`.`user_name` LIKE '%li%' )
|
||||||
List<Account> accounts = MybatisFlexBootstrap.getInstance()
|
List<Account> accounts = MybatisFlexBootstrap.getInstance()
|
||||||
.execute(AccountMapper.class, mapper ->
|
.execute(AccountMapper.class, mapper ->
|
||||||
mapper.selectListByQuery(query)
|
mapper.selectListByQuery(query)
|
||||||
@ -101,7 +101,8 @@ class HelloWorld {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
示例3:分页查询
|
e.g.3: paging query
|
||||||
|
|
||||||
```java
|
```java
|
||||||
class HelloWorld {
|
class HelloWorld {
|
||||||
public static void main(String... args) {
|
public static void main(String... args) {
|
||||||
@ -116,8 +117,7 @@ class HelloWorld {
|
|||||||
.addMapper(AccountMapper.class)
|
.addMapper(AccountMapper.class)
|
||||||
.start();
|
.start();
|
||||||
|
|
||||||
// 示例3:分页查询
|
//use QueryWrapper to build query conditions
|
||||||
// 查询第 5 页,每页 10 条数据,通过 QueryWrapper 构建条件查询
|
|
||||||
QueryWrapper query = QueryWrapper.create()
|
QueryWrapper query = QueryWrapper.create()
|
||||||
.select()
|
.select()
|
||||||
.from(ACCOUNT)
|
.from(ACCOUNT)
|
||||||
@ -125,7 +125,7 @@ class HelloWorld {
|
|||||||
.and(ACCOUNT.USER_NAME.like("张").or(ACCOUNT.USER_NAME.like("李")))
|
.and(ACCOUNT.USER_NAME.like("张").or(ACCOUNT.USER_NAME.like("李")))
|
||||||
.orderBy(ACCOUNT.ID.desc());
|
.orderBy(ACCOUNT.ID.desc());
|
||||||
|
|
||||||
// 执行 SQL:
|
// execute SQL:
|
||||||
// ELECT * FROM `tb_account`
|
// ELECT * FROM `tb_account`
|
||||||
// WHERE `tb_account`.`id` >= 100
|
// WHERE `tb_account`.`id` >= 100
|
||||||
// AND (`tb_account`.`user_name` LIKE '%张%' OR `tb_account`.`user_name` LIKE '%李%' )
|
// AND (`tb_account`.`user_name` LIKE '%张%' OR `tb_account`.`user_name` LIKE '%李%' )
|
||||||
|
|||||||
142
readme_zh.md
Normal file
142
readme_zh.md
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
|
||||||
|
# Mybatis-Flex 一个优雅的 Mybatis 增强框架
|
||||||
|
|
||||||
|
## 特征
|
||||||
|
|
||||||
|
- 1、很轻量,整个框架只依赖 Mybatis 再无其他任何第三方依赖
|
||||||
|
- 2、Entity 类基本的增删改查、分页查询
|
||||||
|
- 3、Row 通用映射支持,可以无需实体类对数据库进行增删改查
|
||||||
|
- 4、支持多种数据库类型,自由通过方言持续扩展
|
||||||
|
- 5、支持联合主键,以及不同的主键下的主键内容生成策略
|
||||||
|
- 6、极其友好的 SQL 联动查询,IDE 自动提示不再担心出错
|
||||||
|
- 7、以及更多小惊喜
|
||||||
|
|
||||||
|
## hello world
|
||||||
|
|
||||||
|
**实体类**
|
||||||
|
|
||||||
|
```java
|
||||||
|
|
||||||
|
@Table("tb_account")
|
||||||
|
public class Account {
|
||||||
|
|
||||||
|
@Id()
|
||||||
|
private Long id;
|
||||||
|
private String userName;
|
||||||
|
private Date birthday;
|
||||||
|
private int sex;
|
||||||
|
|
||||||
|
//getter setter
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**AccountMapper 类**
|
||||||
|
|
||||||
|
```java
|
||||||
|
public interface AccountMapper extends BaseMapper<Account> {
|
||||||
|
//只需定义 Mapper 接口即可,可以无任何内容。
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Hello world**
|
||||||
|
|
||||||
|
示例 1:查询 1 条数据
|
||||||
|
```java
|
||||||
|
class HelloWorld {
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
HikariDataSource dataSource = new HikariDataSource();
|
||||||
|
dataSource.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/mybatis-flex");
|
||||||
|
dataSource.setUsername("username");
|
||||||
|
dataSource.setPassword("password");
|
||||||
|
|
||||||
|
MybatisFlexBootstrap.getInstance()
|
||||||
|
.setDatasource(dataSource)
|
||||||
|
.addMapper(AccountMapper.class)
|
||||||
|
.start();
|
||||||
|
|
||||||
|
|
||||||
|
//示例1:查询 id=100 条数据
|
||||||
|
Account account = MybatisFlexBootstrap.getInstance()
|
||||||
|
.execute(AccountMapper.class, mapper ->
|
||||||
|
mapper.selectOneById(100)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
示例2:查询列表
|
||||||
|
|
||||||
|
```java
|
||||||
|
class HelloWorld {
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
HikariDataSource dataSource = new HikariDataSource();
|
||||||
|
dataSource.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/mybatis-flex");
|
||||||
|
dataSource.setUsername("username");
|
||||||
|
dataSource.setPassword("password");
|
||||||
|
|
||||||
|
MybatisFlexBootstrap.getInstance()
|
||||||
|
.setDatasource(dataSource)
|
||||||
|
.addMapper(AccountMapper.class)
|
||||||
|
.start();
|
||||||
|
|
||||||
|
//示例2:通过 QueryWrapper 构建条件查询数据列表
|
||||||
|
QueryWrapper query = QueryWrapper.create()
|
||||||
|
.select()
|
||||||
|
.from(ACCOUNT)
|
||||||
|
.where(ACCOUNT.ID.ge(100))
|
||||||
|
.and(ACCOUNT.USER_NAME.like("张").or(ACCOUNT.USER_NAME.like("李")));
|
||||||
|
|
||||||
|
// 执行 SQL:
|
||||||
|
// ELECT * FROM `tb_account`
|
||||||
|
// WHERE `tb_account`.`id` >= 100
|
||||||
|
// AND (`tb_account`.`user_name` LIKE '%张%' OR `tb_account`.`user_name` LIKE '%李%' )
|
||||||
|
List<Account> accounts = MybatisFlexBootstrap.getInstance()
|
||||||
|
.execute(AccountMapper.class, mapper ->
|
||||||
|
mapper.selectListByQuery(query)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
示例3:分页查询
|
||||||
|
```java
|
||||||
|
class HelloWorld {
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
HikariDataSource dataSource = new HikariDataSource();
|
||||||
|
dataSource.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/mybatis-flex");
|
||||||
|
dataSource.setUsername("username");
|
||||||
|
dataSource.setPassword("password");
|
||||||
|
|
||||||
|
MybatisFlexBootstrap.getInstance()
|
||||||
|
.setDatasource(dataSource)
|
||||||
|
.addMapper(AccountMapper.class)
|
||||||
|
.start();
|
||||||
|
|
||||||
|
// 示例3:分页查询
|
||||||
|
// 查询第 5 页,每页 10 条数据,通过 QueryWrapper 构建条件查询
|
||||||
|
QueryWrapper query = QueryWrapper.create()
|
||||||
|
.select()
|
||||||
|
.from(ACCOUNT)
|
||||||
|
.where(ACCOUNT.ID.ge(100))
|
||||||
|
.and(ACCOUNT.USER_NAME.like("张").or(ACCOUNT.USER_NAME.like("李")))
|
||||||
|
.orderBy(ACCOUNT.ID.desc());
|
||||||
|
|
||||||
|
// 执行 SQL:
|
||||||
|
// ELECT * FROM `tb_account`
|
||||||
|
// WHERE `tb_account`.`id` >= 100
|
||||||
|
// AND (`tb_account`.`user_name` LIKE '%张%' OR `tb_account`.`user_name` LIKE '%李%' )
|
||||||
|
// ORDER BY `tb_account`.`id` DESC
|
||||||
|
// LIMIT 40,10
|
||||||
|
Page<Account> accounts = MybatisFlexBootstrap.getInstance()
|
||||||
|
.execute(AccountMapper.class, mapper ->
|
||||||
|
mapper.paginate(5, 10, query)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user