概述
在Springboot项目中使用Oceanbase4.2版本数据库。
pom
PS:可在maven仓库中搜索oceanbase,第一个就是。
<dependency>
<groupId>com.oceanbase</groupId>
<artifactId>oceanbase-client</artifactId>
<version>2.4.4</version>
</dependency>
配置
spring:
dataSource:
driver-class-name: com.alipay.oceanbase.jdbc.Driver
url: jdbc:oceanbase://192.169.1.200:2883/psm
username: root@psm
password: 123456
代码测试
package com.example.test_connect_oceanbase.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.test_connect_oceanbase.dao.Test_tableDao;
import com.example.test_connect_oceanbase.pojo.TEST_TABLE;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import javax.annotation.PostConstruct;
import java.util.List;
@Controller
@Slf4j
public class TestConnectController
{
@Autowired
Test_tableDao test_tableDao;
@PostConstruct
void initTask()
{
//查询当前
List<TEST_TABLE> testTableList = test_tableDao.selectList(null);
System.out.println( "before testTableList: \t" + testTableList );
//新增一条记录
TEST_TABLE testTable = new TEST_TABLE( 111, "new name" );
QueryWrapper<TEST_TABLE> queryWrapper = new QueryWrapper<>();
queryWrapper.eq( "id", 111 );
test_tableDao.delete( queryWrapper );
test_tableDao.insert( testTable );
//查询当前
testTableList = test_tableDao.selectList(null);
System.out.println( "after testTableList: \t" + testTableList );
}
}
标签:集成,Springboot,oceanbase,testTableList,tableDao,test,import,com,OceanBase4
From: https://blog.51cto.com/weiyuqingcheng/7420803