sprinboot+tk.mybatis集成人大金仓kingbase数据库

1.首先需要找到jar包

链接:https://pan.baidu.com/s/1LXE-4di6Dieuw5hfXrKIqg 
提取码:j3r4 

2.导入到本地mvn本地仓库

mvn install:install-file -Dfile=E:\jar\kingbase8-8.2.0.jar -DgroupId=com.kingbase8 -DartifactId=kingbase8 -Dversion=8.2.0 -Dpackaging=jar

3.在pom.xml中引用


            com.alibaba
            druid
            1.1.9
        

        
            com.kingbase8
            kingbase8
            8.2.0
        

这里使用的是阿里的连接池下载稍微高点的版本支持人大金仓数据库

4.在配置文件中配置连接

jdbc2:
  url: jdbc:kingbase8://192.168.163.177:54321/ACCP
  username: SYSTEM
  password: 123456
  driverClassName: com.kingbase8.Driver

5.创建实体类

package com.netintech.web.app.bean;

import com.netintech.web.bean.PagesStatic;
import lombok.Data;

import javax.persistence.Table;
import java.io.Serializable;

@Data
@Table(name="\"PUBLIC\".\"dict_u\"")
public class Dictu  extends PagesStatic implements Serializable {
    private Integer id;
    private Integer uuid;
    private String name;
}

这边要注意的是表名的写法@Table(name="\"PUBLIC\".\"dict_u\"")一定要这样因为什么原因我还没研究,如果有用过的可以给我留言说下谢谢哈 共同学习(找到原因不这样写的话数据库表名一定要全大写)

6.创建mapper

package com.netintech.web.app.mapper;

import com.netintech.web.app.bean.Dictu;
import com.netintech.web.common.mybatis.MyBaseMapper;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface DictuMapper extends MyBaseMapper {
}

7.创建service

package com.netintech.web.app.service;

import com.netintech.web.app.bean.Dictu;
import com.netintech.web.app.mapper.DictuMapper;
import com.netintech.web.common.mybatis.DatabaseContextHolder;
import com.netintech.web.common.mybatis.DatabaseType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class DictuService {
    @Autowired
    DictuMapper dictuMapper;

    public List getAll(){
        DatabaseContextHolder.close();
        DatabaseContextHolder.setDatabaseType(DatabaseType.TDB);
        return dictuMapper.selectAll();
    }

    public void insert(Dictu d){
        DatabaseContextHolder.close();
        DatabaseContextHolder.setDatabaseType(DatabaseType.TDB);
        dictuMapper.insert(d);
    }

    public void del(Dictu d){
        DatabaseContextHolder.close();
        DatabaseContextHolder.setDatabaseType(DatabaseType.TDB);
        dictuMapper.delete(d);
    }

    public void saveAll(List list){
        DatabaseContextHolder.close();
        DatabaseContextHolder.setDatabaseType(DatabaseType.TDB);
        dictuMapper.insertList(list);
    }
}
DatabaseContextHolder.close();
DatabaseContextHolder.setDatabaseType(DatabaseType.TDB);

这里我是配置的多数据源切换数据库的

 

以上就可以使用增删改查的方法了。也可以在xml中自己写sql语句

你可能感兴趣的:(JAVA开发技术心得,Mybatis)