Mybatis-Flex优雅的 Mybatis 增强框架
Mybatis-Flex 是一个优雅的 Mybatis 增强框架。
特征
- 很轻量,整个框架只依赖 Mybatis 再无其他第三方依赖
- Entity 类的基本增删改查、以及分页查询
- Row 通用映射支持,可以无需实体类对数据库进行增删改查
- 支持多种数据库类型,自由通过方言持续扩展
- 支持联合主键,以及不同的主键内容生成策略
- 极其友好的 SQL 联动查询,IDE 自动提示不再担心出错
- 更多小惊喜
hello world
第一步:编写 Entity 实体类
@Table("tb_account") public class Account { @Id() private Long id; private String userName; private Date birthday; private int sex; //getter setter }
第二步,编写 Mapper 类,并继承 BaseMapper
public interface AccountMapper extends BaseMapper<Account> { //只需定义 Mapper 接口即可,可以无任何内容。 }
第三步:开始查询数据
示例 1:查询 1 条数据
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:查询列表
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:分页查询
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) ); } }
评论
Kungfu优雅的 JFinal 增强框架
Kungfu 是一个优雅的JFinal增强框架,值得拥有。特性:易学易用基于JFinal构建标准MVCJavaWeb项目,提供极易上手的开发库封装和标准接口文档。强大脚手架提供代码生成能力,使用极度简
Kungfu优雅的 JFinal 增强框架
0
easy-mybatisMybatis 的增强框架
easy-mybatis是一个对Mybatis的增强框架(插件)。在Spring集成Mybatis的基础上,将项目开发中对数据库的常用操作统一化。使用本框架可以很便捷的对数据库进行操作,提高开发效率,
easy-mybatisMybatis 的增强框架
0
econageBatismybatis 的增强框架
社区里已经有不少mybatis的增强框架,基本上需要spring支持,并且jdk的版本需要7,而且大多数oracle分页插件在oracle数据库上,没有对行号做预置参数处理。总之社区的mybatis难
econageBatismybatis 的增强框架
0
scofier-simplecurd增强 Mybatis 中的 Mapper
SimpleCurd 是一个增强 Mybatis 中 Mapper 的工具。使用Mybatis,通常
scofier-simplecurd增强 Mybatis 中的 Mapper
0
scofier-simplecurd增强 Mybatis 中的 Mapper
SimpleCurd是一个增强Mybatis中Mapper的工具。使用Mybatis,通常需要写Entity,Mapper(java、xml),对于小项目很麻烦,有没有只写Entity就可以进行CUR
scofier-simplecurd增强 Mybatis 中的 Mapper
0