三、springboot集成达梦
1、数据库中创建表
1、数据库中创建表 CREATE TABLE TEST_BLOCK_T ( BLOCK_ID VARCHAR2(10 BYTE) PRIMARY KEY, --编码 BLOCK_NAME VARCHAR2(200 BYTE) --资源名称 ); Insert into TEST_BLOCK_T (BLOCK_ID, BLOCK_NAME) Values ('1', '哈哈哈'); COMMIT;
2、找到达梦数据库的驱动文件
达梦的安装路径下找到驱动文件
/***************************************
* 达梦8 JDBC驱动版本说明
/***************************************
1. DmJdbcDriver16 对应 Jdk1.6 及以上环境
2. DmJdbcDriver17 对应 Jdk1.7 及以上环境
3. DmJdbcDriver18 对应 Jdk1.8 及以上环境
3、引入驱动文件
引入驱动文件有两种方法
方法一
jar包放入工程里
依赖文件这么写
<dependency> <groupId>com.dm</groupId> <artifactId>Dm8JdbcDriver</artifactId> <version>1.8</version> <scope>system</scope> <systemPath>${project.basedir}/src/lib/DmJdbcDriver18.jar</systemPath> </dependency>
方法二
使用mvn的命令将jar包安装包本地仓库里
Mvn install:install-file -Dfile=D:\DmJdbcDriver18.jar -DgroupId=com.dm -DartifactId=Dm8JdbcDriver -Dversion=1.8 -Dpackaging=jar
依赖文件这么写
<dependency> <groupId>com.dm</groupId> <artifactId>Dm8JdbcDriver</artifactId> <version>1.8</version> </dependency>
4、pom.xml文件
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.3.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <version>2.3.0.RELEASE</version> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> <!-- 集成mybatis-plus --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.3.2</version> </dependency> <!-- 集成达梦驱动jar包方式 --> <!-- <dependency>--> <!-- <groupId>com.dm</groupId>--> <!-- <artifactId>Dm8JdbcDriver</artifactId>--> <!-- <version>1.8</version>--> <!-- <scope>system</scope>--> <!-- <systemPath>${project.basedir}/src/lib/DmJdbcDriver18.jar</systemPath>--> <!-- </dependency>--> <!-- 集成达梦驱动 本地仓库生成pom文件方式 --> <dependency> <groupId>com.dm</groupId> <artifactId>Dm8JdbcDriver</artifactId> <version>1.8</version> </dependency> </dependencies>
5、配置文件
# 应用名称
spring.application.name=demo
# 应用服务 WEB 访问端口
server.port=8080
spring.datasource.driverClassName=dm.jdbc.driver.DmDriver
spring.datasource.url=jdbc:dm://192.168.0.100:5236/BASE_USER
spring.datasource.username=BASE_USER
spring.datasource.password=BASE_PASSWORD
#mybatis-plus控制台打印sql
mybatis-plus.configuration.log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
6、工程结构
7、源码
package com.example.demo; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication @MapperScan("com.example.demo.mapper") public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } }
package com.example.demo.controller; import com.example.demo.domain.Block; import com.example.demo.mapper.BlockMapper; 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.ResponseBody; import org.springframework.web.bind.annotation.RestController; import java.util.List; @RestController @RequestMapping("/hello") public class HelloController { @Autowired private BlockMapper blockMapper; @GetMapping("/list") @ResponseBody public List index() { //直接调用BaseMapper封装好的CRUD方法,就可实现无条件查询数据 List<Block> list = blockMapper.selectList(null); //循环获取用户数据 for (Block block:list){ //获取用户名称 System.out.println(block.getBlockName()); } return list; } }
package com.example.demo.domain; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @TableName(value = "TEST_BLOCK_T") public class Block { private static final long serialVersionUID = 1L; @TableId private String blockId; private String blockName; public String getBlockId() { return blockId; } public void setBlockId(String blockId) { this.blockId = blockId; } public String getBlockName() { return blockName; } public void setBlockName(String blockName) { this.blockName = blockName; } @Override public String toString() { return "XyDicBlockT{" + "blockId='" + blockId + '\'' + ", blockName='" + blockName + '\'' + '}'; } }
package com.example.demo.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.example.demo.domain.Block; import org.apache.ibatis.annotations.Mapper; @Mapper public interface BlockMapper extends BaseMapper<Block> { }
8、测试
源码获取方式(免费):
(1)登录-注册:http://resources.kittytiger.cn/
(2)签到获取积分
(3)搜索:it白话-springboot集成达梦
资源丰富的的网盘资源:网盘资源大全! 推荐一个适合零基础学习SQL的网站:不用安装数据库,在线轻松学习SQL!