BeetlSQL的目标是提供开发高效,维护高效,运行高效的数据库访问框架,在一个系统多个库的情况下,提供一致的编写代码方式。支持如下数据平台
BeetlSQL 不仅仅是简单的类似MyBatis或者是Hibernate,或者是二者的综合,BeetlSQL远大理想是对标甚至超越Spring Data,是实现数据访问统一的框架,无论是传统数据库,还是大数据,还是查询引擎或者时序库,内存数据库。
官网资料:https://www.kancloud.cn/xiandafu/beetlsql3_guide/3033051
项目适配的gitee地址:https://gitee.com/gy297879328/beetlsql3.x_dm 代码拉下来后,修改application.properties中达梦连接串可以直接跑项目
CREATE TABLE "SYS_USER" (
"id" INT NOT NULL,
"name" varchar(255) DEFAULT NULL,
"department_id" int DEFAULT NULL,
"create_time" date DEFAULT NULL,
PRIMARY KEY ("id")
) ;
INSERT INTO "SYS_USER" VALUES (1, 'lijz', 1, NULL);
INSERT INTO "SYS_USER" VALUES (2, 'lucy', 1, NULL);
INSERT INTO "SYS_USER" VALUES (3, 'bear', 2, NULL);
INSERT INTO "SYS_USER" VALUES (4, 'mike', 1, NULL);
INSERT INTO "SYS_USER" VALUES (5, 'lisan', 1, NULL);
INSERT INTO "SYS_USER" VALUES (6, 'xb', 1, NULL);
INSERT INTO "SYS_USER" VALUES (7, 'duanwu', 2, NULL);
INSERT INTO "SYS_USER" VALUES (8, 'fenh', 1, NULL);
INSERT INTO "SYS_USER" VALUES (9, 'lj', 2, NULL);
INSERT INTO "SYS_USER" VALUES (10, 'gshen', 1, NULL);
INSERT INTO "SYS_USER" VALUES (11, 'lihui', 1, NULL);
<dependency>
<groupId>com.ibeetlgroupId>
<artifactId>sql-springboot-starterartifactId>
<version>3.23.3-RELEASEversion>
dependency>
<dependency>
<groupId>com.damenggroupId>
<artifactId>DmJdbcDriver18artifactId>
<version>8.1.2.192version>
dependency>
spring.datasource.url=jdbc:dm://127.0.0.1:5236
spring.datasource.username=SYSDBA
spring.datasource.password=SYSDBA
spring.datasource.driver-class-name=dm.jdbc.driver.DmDriver
beetlsql.sqlManagers=sqlManager1
beetlsql.sqlManager1.ds=ds1
beetlsql.sqlManager1.basePackage=com.dameng.beetlsql3_x_dm
beetlsql.sqlManager1.dbStyle=org.beetl.sql.core.db.DamengStyle
在com.dameng.beetlsql3_x_dm.DataSource目录下新建连接类
package com.dameng.beetlsql3_x_dm.DataSource;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;
import javax.sql.DataSource;
@Configuration
public class SimpleDataSourceConfig {
@Autowired
ApplicationContext ctx;
@Primary
@Bean(name = "ds1")
public DataSource datasource(Environment env) {
HikariDataSource ds = new HikariDataSource();
ds.setJdbcUrl(env.getProperty("spring.datasource.url"));
ds.setUsername(env.getProperty("spring.datasource.username"));
ds.setPassword(env.getProperty("spring.datasource.password"));
ds.setDriverClassName(env.getProperty("spring.datasource.driver-class-name"));
return ds;
}
}
package com.dameng.beetlsql3_x_dm.Service;
import com.dameng.beetlsql3_x_dm.Domain.UserInfo;
import com.dameng.beetlsql3_x_dm.Mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
@Transactional
public class UserService {
@Autowired
UserMapper userMapper;
public void selectUserList() {
List<UserInfo> allList = userMapper.all();
System.out.println(allList);
}
}