赞
踩
INSERT INTO test.battle(battle."id","nickname","position") VALUES (7,'韩信','打野');
update "TEST"."BATTLE" SET "nickname"='关羽' WHERE battle."id"=2;
select * FROM "TEST"."BATTLE";
delete FROM "TEST"."BATTLE" WHERE battle."id"=7
达梦数据库插入或者修改,以及删除数据后要查询数据,刷新数据表格提交事务,否则数据不会更新。
spring boot +mybatis plus 项目构建
1.pom.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.7.4</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
- <groupId>com.example</groupId>
- <artifactId>dmDemo</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <name>dmDemo</name>
- <description>dmDemo</description>
- <properties>
- <java.version>1.8</java.version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-devtools</artifactId>
- <scope>runtime</scope>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- <!-- 引入jdbc支持 -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-jdbc</artifactId>
- </dependency>
- <!-- 引入web支持 -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <!-- 添加 dm8 jdbc jar 包依赖-->
- <!-- https://mvnrepository.com/artifact/com.dameng/Dm8JdbcDriver18 -->
- <dependency>
- <groupId>com.dameng</groupId>
- <artifactId>Dm8JdbcDriver18</artifactId>
- <version>8.1.0.157</version>
- </dependency>
- <dependency>
- <groupId>com.baomidou</groupId>
- <artifactId>mybatis-plus-boot-starter</artifactId>
- <version>3.4.1</version>
- </dependency>
- </dependencies>
-
- <repositories>
- <!-- 使用阿里云镜像仓库用来提高下载速度-->
- <repository>
- <id>aliyun</id>
- <name>aliyun Repository</name>
- <url>http://maven.aliyun.com/nexus/content/groups/public</url>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- </repository>
- <!-- 使用 DM 的镜像仓库来下载驱动包-->
- <repository>
- <id>dc</id>
- <name>dc Repository</name>
- <url>http://119.96.92.173:8181/repository/maven-releases/</url>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- </repository>
- </repositories>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- <configuration>
- <excludes>
- <exclude>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- </exclude>
- </excludes>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- </project>

2.application.properites文件
- spring.datasource.url=jdbc:dm://localhost:5236?SCHEMA=TEST
- spring.datasource.username=SYSDBA
- spring.datasource.password=SYSDBA
- spring.datasource.driver-class-name=dm.jdbc.driver.DmDriver
3.实体类
- package com.example.dmdemo.entity;
-
- import com.baomidou.mybatisplus.annotation.IdType;
- import com.baomidou.mybatisplus.annotation.TableField;
- import com.baomidou.mybatisplus.annotation.TableId;
- import com.baomidou.mybatisplus.annotation.TableName;
- import lombok.AllArgsConstructor;
- import lombok.Data;
- import lombok.NoArgsConstructor;
-
- /**
- * @author welcome
- */
- @Data
- @AllArgsConstructor
- @NoArgsConstructor
- @TableName(value = "\"TEST\".\"battle\"")
- public class Battle {
- @TableId(value = "id",type = IdType.AUTO)
- private Integer id;
- @TableField("nickname")
- private String nickname;
- @TableField("position")
- private String position;
- }

4.dao层
- package com.example.dmdemo.mapper;
-
- import com.baomidou.mybatisplus.core.mapper.BaseMapper;
- import com.example.dmdemo.entity.Battle;
- import org.apache.ibatis.annotations.Insert;
- import org.apache.ibatis.annotations.Mapper;
-
-
- /**
- * @author welcome
- */
- @Mapper
- public interface BattleMapper extends BaseMapper<Battle> {
- @Insert("INSERT INTO test.battle(battle.\"id\",\"nickname\",\"position\") VALUES (#{id},#{nickname},#{position})")
- int insertData(Battle battle);
- }

5.测试类
- package com.example.dmdemo;
-
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.example.dmdemo.entity.Battle;
- import com.example.dmdemo.mapper.BattleMapper;
- import org.junit.jupiter.api.Test;
- import org.springframework.boot.test.context.SpringBootTest;
-
- import javax.annotation.Resource;
- import java.util.List;
-
- @SpringBootTest
- class DmDemoApplicationTests {
- @Resource
- BattleMapper mapper;
- @Test
- void contextLoads() {
- QueryWrapper wrapper=new QueryWrapper<>();
-
- List list = mapper.selectList(wrapper);
- System.out.println(list);
- }
-
- @Test
- void test1(){
- Battle battle=new Battle(12,"金蟾","法师");
- mapper.insertData(battle);
- System.out.println();
- }
- @Test
- void test2(){
- Battle battle=new Battle();
- battle.setId(1);
- battle.setNickname("赵怀真");
- battle.setPosition("战士");
- int i = mapper.updateById(battle);
- }
- @Test
- void test3(){
- int i = mapper.deleteById(11);
-
- }
-
- }

遇到的问题
### Cause: dm.jdbc.driver.DMException: 第1 行附近出现错误:
无效的表或视图名[battle]
原因:注解的表名,没有模式
错误写法:
@TableName("battle")
正确写法:
@TableName(value = "\"TEST\".\"battle\"")
问题2.basemapper自带的插入语句无法使用
解决方式:自己写一个插入语句
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。