simple orm for mybatis

a simple orm tool for mybatis.

License

License

Categories

Categories

ORM Data MyBatis
GroupId

GroupId

com.software5000
ArtifactId

ArtifactId

simple-orm-mybatis
Last Version

Last Version

1.0.4
Release Date

Release Date

Type

Type

jar
Description

Description

simple orm for mybatis
a simple orm tool for mybatis.
Project URL

Project URL

https://github.com/matuobasyouca/simple-orm-mybatis
Source Code Management

Source Code Management

https://github.com/matuobasyouca/simple-orm-mybatis

Download simple-orm-mybatis

How to add to project

<!-- https://jarcasting.com/artifacts/com.software5000/simple-orm-mybatis/ -->
<dependency>
    <groupId>com.software5000</groupId>
    <artifactId>simple-orm-mybatis</artifactId>
    <version>1.0.4</version>
</dependency>
// https://jarcasting.com/artifacts/com.software5000/simple-orm-mybatis/
implementation 'com.software5000:simple-orm-mybatis:1.0.4'
// https://jarcasting.com/artifacts/com.software5000/simple-orm-mybatis/
implementation ("com.software5000:simple-orm-mybatis:1.0.4")
'com.software5000:simple-orm-mybatis:jar:1.0.4'
<dependency org="com.software5000" name="simple-orm-mybatis" rev="1.0.4">
  <artifact name="simple-orm-mybatis" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.software5000', module='simple-orm-mybatis', version='1.0.4')
)
libraryDependencies += "com.software5000" % "simple-orm-mybatis" % "1.0.4"
[com.software5000/simple-orm-mybatis "1.0.4"]

Dependencies

compile (5)

Group / Artifact Type Version
org.mybatis : mybatis jar 3.5.0
org.mybatis : mybatis-spring jar 2.0.0
com.github.pagehelper : pagehelper jar 5.1.8
org.slf4j : slf4j-api jar 1.7.26
com.google.guava : guava jar 27.0.1-jre

Project Modules

There are no modules declared in this project.

这个项目期望是在Mybatis之上做一层简化封装,能够通过后台直接生成sql语句执行针对单表的增删改查语句并且执行。

查看详细说明文档

使用的基础工作

  1. 首先引入依赖
<dependency>
    <groupId>com.software5000</groupId>
    <artifactId>simple-orm-mybatis</artifactId>
    <version>1.0.2</version>
</dependency>
  1. 接着需要将 BaseDaoMapper.xml 文件放在你的 mapper 的扫描文件夹内。

  2. 最后需要在你的代码中添加一个 BaseDao 实现类,用于提供数据库操作服务(注意:需要在spring的扫描包内,因为需要注入某些属性),整个复制即可,类名可以改为你自己需要的名字

import com.software5000.base.BaseDao;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 整个类以 <code>org.mybatis:mybatis-spring:2.0.0</code> 的 <code>org.mybatis.spring.supportSqlSessionDaoSupport</code>
 * 为参考编写而成
 */
@Component
public class MyBaseDao extends BaseDao {
    private SqlSessionTemplate sqlSessionTemplate;
    
    public MyBaseDao() {
            // 在默认构造函数中设置 数据库是否蛇形, 数据库格式大小写, 通用忽略的字段名称
            this.initConfig(true,false,"serialVersionUID");
    }
        
    @Resource
    public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
        if (this.sqlSessionTemplate == null || sqlSessionFactory != this.sqlSessionTemplate.getSqlSessionFactory()) {
            this.sqlSessionTemplate = this.createSqlSessionTemplate(sqlSessionFactory);
        }
    }

    protected SqlSessionTemplate createSqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
        return new SqlSessionTemplate(sqlSessionFactory);
    }

    @Override
    public SqlSession getSqlSession() {
        return this.sqlSessionTemplate;
    }
}

实际使用

这里给了一个单元测试的例子,实际一般是在service层直接使用,无需添加任何代码。 示例中的 DailyRecord是一个普通实体类,没有任何继承。

// 获取启动类,加载配置,确定装载 Spring 程序的装载方法,它回去寻找 主配置启动类(被 @SpringBootApplication 注解的)
@SpringBootTest
// 让 JUnit 运行 Spring 的测试环境, 获得 Spring 环境的上下文的支持
@RunWith(SpringRunner.class)
public class BaseDaoTest {

    @Autowired
    private MyBaseDao myBaseDao;

    @Test
    public void testBaseDao(){
        DailyRecord dailyRecord = new DailyRecord();
        List<DailyRecord> dailyRecords  = myBaseDao.selectEntity(dailyRecord);
        System.out.println(dailyRecords.size());
    }
}


Versions

Version
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0