SpringBoot整合达梦8

借鉴文章连接https://blog.csdn.net/zhouzhiwengang/article/details/120215482?ops_request_misc=&request_id=&biz_id=102&utm_term=springboot%20mybaties%E8%BF%9E%E6%8E%A5%E8%BE%BE%E6%A2%A68&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-3-120215482.142%5Ev73%5Einsert_down4,201%5Ev4%5Eadd_ask,239%5Ev1%5Einsert_chatgpt&spm=1018.2226.3001.4187

1.配置数据源

 url配置

jdbc:dm://127.0.0.1:5236/test?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8

 2.maven配置 很重要 很重要 很重要

在idea右侧边栏maven中点击 m(执行maven目标)输入

其中Dfile 后面跟的是DmJdbcDriver18.jar 包存放的文件夹路径

jar包是达梦数据库中自带的

mvn install:install-file -Dfile=D:\mongodb\DM8SSSS\src\lib\DmJdbcDriver18.jar -DgroupId=dm.jdbc -DartifactId=DmJdbcDriver18 -Dversion=18 -Dpackaging=jar

 3.pom.xml文件中添加依赖

第二部没有执行,第三部会报错

<!-- 达梦数据库驱动  -->
<dependency>
    <groupId>dm.jdbc</groupId>
    <artifactId>DmJdbcDriver18</artifactId>
    <version>18</version>
</dependency>

4. application.properties配置

test 我的数据库

spring.datasource.driver-class-name=dm.jdbc.driver.DmDriver
spring.datasource.url=jdbc:dm://127.0.0.1:5236/test?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8
spring.datasource.username=SYSDBA
spring.datasource.password=SYSDBA

5.达梦数据库数据

6.idea调用 

6.1 pom.xml文件

        <!-- 达梦数据库驱动  -->
        <dependency>
            <groupId>dm.jdbc</groupId>
            <artifactId>DmJdbcDriver18</artifactId>
            <version>18</version>
        </dependency>

        <!--springboot-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!--简化代码-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>

        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.2.2</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.github.jsqlparser</groupId>
            <artifactId>jsqlparser</artifactId>
            <version>4.3</version>
        </dependency>

6.2 application.properties

mybatis.mapper-locations=classpath:mapper/*.xml

 6.3 启动类添加

@MapperScan(value = "com.skx.dm8ssss.mapper")

 6.4 实体类

package com.skx.dm8ssss.entiy;
import lombok.Data;
import java.io.Serializable;
/**
 * 员工表
 * @author 阿新
 */
@Data
public class Emp implements Serializable {
    private Long empId;
    private String empName;
    private String jobId;
    private Integer salay;
    private Long deptId;
}

6.5 controller

package com.skx.dm8ssss.controller;

import com.skx.dm8ssss.entiy.Emp;
import com.skx.dm8ssss.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * 测试达梦数据库
 * @author 阿新
 */
@RestController
@RequestMapping("skx")
public class TestController {

    @Autowired
    private TestService testService;

    //获取数据
    @GetMapping("list")
    public List<Emp> getList(){
        return testService.getList();
    }


}

6.6 service

package com.skx.dm8ssss.service;

import com.skx.dm8ssss.entiy.Emp;
import java.util.List;

public interface TestService {
    //获取数据
    List<Emp> getList();
}

6.7 serviceImpl

package com.skx.dm8ssss.service.impl;

import com.skx.dm8ssss.entiy.Emp;
import com.skx.dm8ssss.mapper.TestMapper;
import com.skx.dm8ssss.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 测试达梦数据库
 * @author 阿新
 */
@Service
public class TestServiceImpl implements TestService {

    @Autowired
    private TestMapper testMapper;

    //获取数据
    @Override
    public List<Emp> getList() {
        return testMapper.getList();

    }
}

6.8 mapper

package com.skx.dm8ssss.mapper;

import com.skx.dm8ssss.entiy.Emp;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 测试达梦数据库
 * @author 阿新
 */
@Repository
public interface TestMapper {
    //获取数据
    List<Emp> getList();
}

6.9 mapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.skx.dm8ssss.mapper.TestMapper">

    <select id="getList" resultMap="sd">
        select * from emp
    </select>

    <resultMap id="sd" type="com.skx.dm8ssss.entiy.Emp">
        <id column="emp_id" jdbcType="VARCHAR" property="empId"/>
        <result column="emp_name" jdbcType="VARCHAR" property="empName"/>
        <result column="job_id" jdbcType="VARCHAR" property="jobId"/>
        <result column="salay" jdbcType="VARCHAR" property="salay"/>
        <result column="dept_id" jdbcType="VARCHAR" property="deptId"/>
    </resultMap>
</mapper>

运行结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值