1 Star 0 Fork 16

hbyc / vonce-sqlbean

forked from imJovi / SqlBean 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Sqlbean

介绍

Sqlbean是一款使用Java面向对象思想来编写并生成Sql语句的工具,在此基础上对Mybatis和Spring Jdbc实现了类似于JPA的轻量级插件支持。其中内置大量常用SQL执行的方法,可以非常方便的达到你想要的目的,相对复杂的SQL语句也得以支持,在常规的项目开发几乎做到不写DAO层,可以有效的提高项目开发的效率,让开发者更专注于业务代码的编写。
🚀特点: 零入侵, 多数据源, 动态Schema, 读写分离, 自动建表, 连表查询, 乐观锁, 分页, 支持Mybatis和Spring Jdbc
💻环境: JDK8+, Mybatis3.2.4+, (Spring MVC 4.1.2+, Spring Boot 1.x, Spring Boot 2.x)
💿数据库: Mysql, MariaDB, Oracle, Sqlserver2008+, PostgreSQL, DB2, Derby, Sqlite, HSQL, H2
Sqlbean For Android请移步这里👉 gitee, github

简单上手

1.引入Maven依赖
<dependency>
	<groupId>cn.vonce</groupId>
	<artifactId>vonce-sqlbean-spring</artifactId>
	<version>1.5.4</version>
</dependency>
2.标注实体类
//标识表名
//标识表名
@SqlTable("d_essay")
public class Essay {
    @SqlId(type = IdType.SNOWFLAKE_ID_16)
    private Long id;
    private String userId;
    private String content;
    private Date creationTime;
    @SqlVersion
    private Date updateTime;
    /**省略get set方法*/
}
3.无需Dao层,Service层接口只需继承SqlBeanService<实体类, ID>
public interface EssayService extends SqlBeanService<Essay, Long> {
    //已内置大量常用查询、更新、删除、插入方法,这里可以写自己封装的方法

}
4.Service实现类只需继承MybatisSqlBeanServiceImpl<实体类, ID>和实现你的Service接口
//使用Spring Jdbc的话将继承的父类改成SpringJdbcSqlBeanServiceImpl即可
@Service
public class EssayServiceImpl extends MybatisSqlBeanServiceImpl<Essay, Long> implements EssayService {

}
5.Controller层
@RequestMapping("essay")
@RestController
public class EssayController {

    @Autowired
    private EssayService essayService;

    //查询
    @GetMapping("select")
    public RS select() {
        //查询列表
        List<Essay> list = essayService.selectAll();
        list = essayService.selectByCondition(Wrapper.where(gt(Essay$.id, 10)).and(lt(Essay$.id, 20)));

        //查询一条
        Essay essay = essayService.selectById(1L);
        essay = essayService.selectOneByCondition(Wrapper.where(eq(Essay$.id, 333)));

        //复杂查询
        Select select = new Select();
        select.column(Essay$.id).column(Essay$.content);
        select.where().gt("id", 1).and().eq("content", "222");
        select.orderBy("id", SqlSort.DESC);
        list = essayService.select(select);

        //用于查询Map
        Map<String, Object> map = essayService.selectMap(select);
        List<Map<String, Object>> mapList = essayService.selectMapList(select);

        return super.successHint("获取成功", list);
    }

    //分页
    @GetMapping("getList")
    public Map getList(HttpServletRequest request) {
        // 查询对象
        Select select = new Select();
        ReqPageHelper<Essay> pageHelper = new ReqPageHelper<>(request);
        pageHelper.paging(select, essayService);
        return pageHelper.toResult("获取列表成功");
    }

    //更新
    @PostMapping("update")
    public RS update(Essay essay) {
        //根据bean内部id更新
        long i = essayService.updateByBeanId(essay);
        //根据条件更新
        //i = essayService.updateByCondition(Wrapper.where(gt(Essay$.id, 1)).and(eq(Essay$.content, "222")));
        if (i > 0) {
            return super.successHint("更新成功");
        }
        return super.othersHint("更新失败");
    }

    //删除
    @PostMapping("deleteById")
    public RS deleteById(Integer[] id) {
        //根据id删除
        long i = essayService.deleteById(id);
        //根据条件删除
        //i = essayService.deleteByCondition(Wrapper.where(gt(Essay$.id, 1)).and(eq(Essay$.content, "222")));

        if (i > 0) {
            return super.successHint("删除成功");
        }
        return super.othersHint("删除失败");
    }

    //插入
    @PostMapping("add")
    public RS add() {
        List<Essay> essayList = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            Essay essay = new Essay(i, "name" + i);
            essayList.add(essay);
        }
        essayService.insert(essayList);
        return successHint("成功");
    }

}
👇👇👇更多用法请查看下方文档👇👇👇

文档说明

0️⃣. 注解详情与使用
1️⃣. Select
2️⃣. Insert
3️⃣. Delete
4️⃣. Update
5️⃣. 表操作相关
6️⃣. 分页查询
7️⃣. Service接口和实现类
8️⃣. SqlBean和SqlHelper
9️⃣. Where条件和包装器
🔟. 多数据源动态Schema读写分离相关配置
MIT License Copyright (c) 2019 Jovilam77 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Sqlbean是一款使用Java面向对象思想来编写并生成Sql语句的工具,在此基础上对Mybatis和Spring Jdbc实现了类似于JPA的轻量级插件支持,无需编写DAO层,助你快速进行项目开发。 展开 收起
Java
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/hbycqm/vonce-sqlbean.git
git@gitee.com:hbycqm/vonce-sqlbean.git
hbycqm
vonce-sqlbean
vonce-sqlbean
master

搜索帮助