欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Mybatis整合達(dá)夢(mèng)數(shù)據(jù)庫(kù)的完整步驟記錄

 更新時(shí)間:2023年02月01日 10:41:41   作者:陳老老老板  
作為國(guó)產(chǎn)數(shù)據(jù)庫(kù),達(dá)夢(mèng)做的不錯(cuò),提供的遷移工具也相當(dāng)不錯(cuò),下面這篇文章主要給大家介紹了關(guān)于Mybatis整合達(dá)夢(mèng)數(shù)據(jù)庫(kù)的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下

一、達(dá)夢(mèng)數(shù)據(jù)庫(kù)簡(jiǎn)介

說(shuō)明:有關(guān)國(guó)產(chǎn)數(shù)據(jù)庫(kù)完整的博客太少了,所以就想弄一個(gè)完整的專欄給大家提供一些幫助。在現(xiàn)在這種國(guó)際形勢(shì)下,網(wǎng)絡(luò)安全是每個(gè)企業(yè),乃至整個(gè)國(guó)家重中之重的事,國(guó)產(chǎn)化是一種趨勢(shì),在整合之前先了解一下達(dá)夢(mèng)數(shù)據(jù)庫(kù)。達(dá)夢(mèng)數(shù)據(jù)庫(kù)官網(wǎng):本篇主要講整合,詳細(xì)介紹會(huì)在別的文章中。

1.達(dá)夢(mèng)數(shù)據(jù)庫(kù)管理系統(tǒng)是達(dá)夢(mèng)公司推出的具有完全自主知識(shí)產(chǎn)權(quán)的高性能數(shù)據(jù)庫(kù)管理系統(tǒng),簡(jiǎn)稱DM。
達(dá)夢(mèng)數(shù)據(jù)庫(kù)管理系統(tǒng)的最新版本是8.0版本,簡(jiǎn)稱DM8。

2.DM8采用全新的體系架構(gòu),在保證大型通用的基礎(chǔ)上,針對(duì)可靠性、高性能、海量數(shù)據(jù)處理和安全性做了大量的研發(fā)和改進(jìn)工作,極大提升了達(dá)夢(mèng)數(shù)據(jù)庫(kù)產(chǎn)品的性能、可靠性、可擴(kuò)展性,能同時(shí)兼顧OLTP和OLAP請(qǐng)求,從根本上提升了DM8產(chǎn)品的品質(zhì)。

二、Mybatis整合達(dá)夢(mèng)數(shù)據(jù)庫(kù)

說(shuō)明:本篇使用的是SpringBoot框架+JPA+達(dá)夢(mèng)數(shù)據(jù)庫(kù)的整合。

項(xiàng)目運(yùn)行環(huán)境:

  • idea2020.2
  • DM8
  • jdk1.8
  • springboot 2.3.12.RELEASE

1、創(chuàng)建項(xiàng)目

其實(shí)創(chuàng)建項(xiàng)目可以省略的,但是還是給大家展示出來(lái)吧。詳細(xì)的步驟就不啰嗦了。

注:選擇組件就選lombok就OK了。其實(shí)我項(xiàng)目中使用的是springboot2.3.12.RELEASE,因?yàn)檫m配用,非常的穩(wěn)定。大家自己改用項(xiàng)目版本就可以了。

2、添加坐標(biāo)

注:mybatis-spring-boot-starter不用寫version就按springboot版本適配就行,而Dm8JdbcDriver18是8以上版本。

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

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

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        
		<!--達(dá)夢(mèng)數(shù)據(jù)庫(kù)驅(qū)動(dòng)-->
        <dependency>
            <groupId>com.dameng</groupId>
            <artifactId>Dm8JdbcDriver18</artifactId>
            <version>8.1.1.49</version>
        </dependency>

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

    </dependencies>

項(xiàng)目截圖:

3.編寫配置文件

注:這里需要先創(chuàng)建一個(gè)ZY的模式,在模式下創(chuàng)建一個(gè)TESTDB1的表,表中字段:自增Integer id,String name。和一個(gè)叫ZY的用戶名密碼是123456789,這里按自己的更改就可以了,mapper-locations要注意自己的mapper的位置進(jìn)行更改。

spring:
  datasource:
    url: jdbc:dm://127.0.0.1:5236?schema=ZY
    username: ZY
    password: 123456789
    driver-class-name: dm.jdbc.driver.DmDriver
mybatis:
#  注意這里按自己的mapper文件位置進(jìn)行更改
  mapper-locations: classpath*:mapper/*Mapper.xml

這里給大家看一下我的項(xiàng)目結(jié)果,mapper的位置和yml文件。

4.編寫實(shí)體類

注:這里如果對(duì)mybatis了解的話,就需要寫一個(gè)實(shí)體類與數(shù)據(jù)庫(kù)表進(jìn)行映射。這里是在ZY的模式下,TESTDB1表的字段id,name。這里按自己創(chuàng)建的庫(kù)改也沒問(wèn)題。

@Data
public class TestDB1 {
    private Integer id;
    private String name;
}

項(xiàng)目截圖:

5.Mapper類(dao)

注:這里要注意要寫@Mapper注解,才能與mapper中的sql進(jìn)行映射。這里是四個(gè)方法查詢、新增、修改、刪除。

@Mapper
public interface TestDB1Mapper {
    List<TestDB1> select (Integer id);
    void save(String name);
    void update(@Param("id") Integer id,@Param("name") String name);
    void delete(Integer id);
}

項(xiàng)目截圖:

6.Mapper.xml文件

注:這里需要注意namespace 要與Mapper類映射。id要與Mapper類中的方法名映射。

<?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.sql.mybatisdm.mapper.TestDB1Mapper">
    <insert id="save">
        insert into testdb1(name) values(#{name});
    </insert>

    <select id="select" resultType="com.sql.mybatisdm.domain.TestDB1">
        select id,name from testdb1 where id = #{id}
    </select>

    <update id="update" >
        update TESTDB1  set NAME = #{name} where id = #{id};
    </update>

    <delete id="delete">
        delete from TESTDB1 where id = #{id};
    </delete>
</mapper>

項(xiàng)目截圖:

7.Test測(cè)試文件

注:這些方法要新填入數(shù)據(jù),在進(jìn)行其他的操作。都是ok的直接用就行,如果有問(wèn)題可以私信我。

@SpringBootTest
class MybatisdmApplicationTests {

    @Autowired
    private TestDB1Mapper testDB1Mapper;

    /**
     * 保存
     */
    @Test
    void save() {
       testDB1Mapper.save("clllb");

        List<TestDB1> select = testDB1Mapper.select(1);
        System.out.println(select);
    }

    /**
     * 查詢
     */
    @Test
    void select(){
        List<TestDB1> select = testDB1Mapper.select(2);
        System.out.println(select);
    }

    /**
     * 修改
     */
    @Test
    void update() {
        testDB1Mapper.update(1,"CLLLB");

        List<TestDB1> select = testDB1Mapper.select(1);
        System.out.println(select);
    }

    /**
     * 刪除
     */
    @Test
    void delete(){
        testDB1Mapper.delete(1);

        List<TestDB1> select = testDB1Mapper.select(1);
        System.out.println(select);

    }
}

項(xiàng)目截圖:

總結(jié)

到此這篇關(guān)于Mybatis整合達(dá)夢(mèng)數(shù)據(jù)庫(kù)的文章就介紹到這了,更多相關(guān)Mybatis整合達(dá)夢(mèng)數(shù)據(jù)庫(kù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論