sprinboot+tk.mybatis集成达梦DM8数据库

1.首先下载jdbc的jar包

链接:https://pan.baidu.com/s/1HZXGI_KI9p4pasT4djnryA 
提取码:yz5h 

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

mvn install:install-file -Dfile=E:\jar\DmJdbcDriver18.jar -DgroupId=dm.jdbc -DartifactId=DmJdbcDriver18 -Dversion=18 -Dpackaging=jar

3.在pom.xml中引用

        
            com.alibaba
            druid
            1.1.9
        
        
            dm.jdbc
            DmJdbcDriver18
            18
        

这里使用的是阿里的连接池下载稍微高点的版本支持达梦数据库

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

jdbc3:
  url: jdbc:dm://172.16.3.11:5236/DAMENG
  username: SYSDBA
  password: netmarch@2019
  driverClassName: dm.jdbc.driver.DmDriver

5.创建实体类

package com.netintech.web.app.bean;

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

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

@Data
@Table(name="accp.userstype")
public class UsersType extends PagesStatic implements Serializable {
    @Id
    private Integer id = 1;
    private String name;
    private String code;
}

6.创建mapper

package com.netintech.web.app.mapper;

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

import java.util.List;
import java.util.Map;

@Mapper
public interface UsersTypeMapper extends MyBaseMapper {
    List getSysUsersTypeList(Map map);
    String getSysUsersTypeListCount(Map map);
}

7.创建mapper的xml文件




    


    


8.创建service

package com.netintech.web.app.service;

import com.netintech.web.app.bean.UsersType;
import com.netintech.web.app.bean.UsersType1;
import com.netintech.web.app.mapper.UsersType1Mapper;
import com.netintech.web.app.mapper.UsersTypeMapper;
import com.netintech.web.bean.PagesStatic;
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.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UsersTypeService {
    @Autowired
    UsersTypeMapper usersTypeMapper;
    @Autowired
    UsersType1Mapper usersType1Mapper;

    public List getSysUsersTypeList(UsersType resource) {
        DatabaseContextHolder.close();
        DatabaseContextHolder.setDatabaseType(DatabaseType.FOUR);
        Map map = new HashMap<>();
        map.put("star",(resource.getPageNo()-1)* PagesStatic.PAGES_SIZE);
        map.put("end",(resource.getPageNo())*PagesStatic.PAGES_SIZE);
        return usersTypeMapper.getSysUsersTypeList(map);
    }

    public String getSysUsersTypeListCount(UsersType resource){
        DatabaseContextHolder.close();
        DatabaseContextHolder.setDatabaseType(DatabaseType.FOUR);
        Map map = new HashMap<>();
        return usersTypeMapper.getSysUsersTypeListCount(map);
    }

    public List getAll(){
        DatabaseContextHolder.close();
        DatabaseContextHolder.setDatabaseType(DatabaseType.FOUR);
        return usersTypeMapper.selectAll();
    }

    public void insert(UsersType1 d){
        DatabaseContextHolder.close();
        DatabaseContextHolder.setDatabaseType(DatabaseType.FOUR);
        usersType1Mapper.insert(d);
    }

    public void del(UsersType d){
        DatabaseContextHolder.close();
        DatabaseContextHolder.setDatabaseType(DatabaseType.FOUR);
        usersTypeMapper.delete(d);
    }

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

 

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